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

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 +951 -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 +734 -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 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAQA,kCAEC;AAED,sCA4BC;AAED,0CAGC;AAED,kCAMC;AAKD,kCAiBC;AAGD,wCAGC;AAYD,8CAUC;AASD,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ources":["../src/utils.ts"],"sourcesContent":["import { pascalCase } from \"change-case\";\nimport { isPlainObject } from \"joist-utils\";\nimport { type Table } from \"pg-structure\";\nimport pluralize from \"pluralize\";\nimport { code, imp } from \"ts-poet\";\n\nimport { type Config, getTimestampConfig } from \"./config.ts\";\nimport { type DatabaseColumnType, type PrimitiveTypescriptType } from \"./EntityDbMetadata.ts\";\n\nexport function assertNever(x: never): never {\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function isEntityTable(config: Config, t: Table): boolean {\n if (isIgnored(config, t) || isJoinTable(config, t)) {\n return false;\n }\n\n // Depending on the config settings, we may/may not require the presence of timestamp\n // fields to determine whether a table is an entity.\n const columnNames = t.columns.map((c) => c.name);\n const { updatedAtConf, createdAtConf } = getTimestampConfig(config);\n const hasCreatedAt = createdAtConf.names.some((c) => columnNames.includes(c));\n const hasUpdatedAt = updatedAtConf.names.some((c) => columnNames.includes(c));\n\n // Entities always require an id column\n const hasIdColumn = columnNames.includes(\"id\");\n if (!hasIdColumn) return false;\n\n // If we have no timestamp columns, but do have `name` and `code`, we're probably an enum.\n if (hasIdColumn && !hasCreatedAt && !hasUpdatedAt) {\n if ([\"name\", \"code\"].every((c) => columnNames.includes(c))) {\n return false;\n }\n }\n\n // If the ID column is a FK then we're a subclass\n if (isSubClassTable(t)) return true;\n\n // Otherwise respect the created_at/updated_at required rules\n return hasIdColumn && (hasCreatedAt || !createdAtConf.required) && (hasUpdatedAt || !updatedAtConf.required);\n}\n\nexport function isSubClassTable(t: Table): boolean {\n // Note that `.get(\"id\")` will blow up if there is no id column\n return t.columns.get(\"id\").foreignKeys.length === 1;\n}\n\nexport function isEnumTable(config: Config, t: Table): boolean {\n if (isIgnored(config, t)) {\n return false;\n }\n const columnNames = t.columns.map((c) => c.name);\n return [\"id\", \"code\", \"name\"].every((c) => columnNames.includes(c)) && !isEntityTable(config, t);\n}\n\n// Oddly enough isJoinTable showed up as a hot spot, so cache its calculation.\nconst joinTables: Map<string, boolean> = new Map();\n\nexport function isJoinTable(config: Config, t: Table): boolean {\n if (isIgnored(config, t)) {\n return false;\n }\n return getOrElse(joinTables, t.name, () => {\n const { columns } = t;\n const fks = columns.filter((c) => c.isForeignKey);\n const pks = columns.filter((c) => c.isPrimaryKey);\n // Every join table is two FKs, plus either a surrogate `id` PK (\"id-ful\") or no surrogate\n // at all, in which case the two FKs are themselves the composite PK (\"id-less\").\n if (fks.length !== 2) return false;\n if (!joinTableHasId(t) && !(pks.length === 2 && pks.every((c) => c.isForeignKey))) return false;\n // Any column beyond the two FKs and the optional `id` PK must be a single created_at.\n const others = columns.length - fks.length - (joinTableHasId(t) ? 1 : 0);\n const createdAts = columns.filter((c) => c.name === \"created_at\" || c.name === \"createdAt\").length;\n return others === 0 || (others === 1 && createdAts === 1);\n });\n}\n\n/** Whether a join table has a surrogate `id` primary key (vs. an id-less FK-pair composite PK). */\nexport function joinTableHasId(t: Table): boolean {\n const pks = t.columns.filter((c) => c.isPrimaryKey);\n return pks.length === 1 && !pks[0].isForeignKey;\n}\n\nfunction getOrElse<K, V>(map: Map<K, V>, key: K, fn: () => V): V {\n let value = map.get(key);\n if (value === undefined) {\n value = fn();\n map.set(key, value);\n }\n return value;\n}\n\n/** Converts `projects` to `Project`. */\nexport function tableToEntityName(config: Config, table: Table): string {\n let entityName = config.__tableToEntityName?.[table.name];\n if (!entityName) {\n const configEntityName = Object.entries(config.entities)\n .filter(([, conf]) => conf.tableName === table.name)\n .map(([entityName]) => entityName)[0];\n entityName = configEntityName || pascalCase(pluralize.singular(table.name));\n (config.__tableToEntityName ??= {})[table.name] = entityName;\n }\n return entityName;\n}\n\nexport const dateCode = code`Date`;\nexport const plainDateCode = code`${imp(\"Temporal@joist-orm\")}.PlainDate`;\nexport const plainTimeCode = code`${imp(\"Temporal@joist-orm\")}.PlainTime`;\nexport const plainDateTimeCode = code`${imp(\"Temporal@joist-orm\")}.PlainDateTime`;\nexport const zonedDateTimeCode = code`${imp(\"Temporal@joist-orm\")}.ZonedDateTime`;\n\n/** Maps db types, i.e. `int`, to JS types, i.e. `number`. */\nexport function mapSimpleDbTypeToTypescriptType(config: Config, dbType: DatabaseColumnType): PrimitiveTypescriptType {\n switch (dbType) {\n case \"boolean\":\n return \"boolean\";\n case \"int\":\n case \"numeric\":\n case \"smallint\":\n case \"integer\":\n case \"decimal\":\n case \"real\":\n case \"smallserial\":\n case \"serial\":\n case \"double precision\":\n return \"number\";\n case \"bigserial\":\n case \"bigint\":\n return \"bigint\";\n case \"text\":\n case \"citext\":\n case \"character varying\":\n case \"varchar\":\n case \"uuid\":\n case \"tsvector\":\n case \"tstzrange\":\n return \"string\";\n case \"time without time zone\":\n return config.temporal\n ? plainTimeCode\n : fail(\"Joist doesn't support 'time without time zone' unless temporal is enabled\");\n case \"timestamp with time zone\":\n return config.temporal ? zonedDateTimeCode : dateCode;\n case \"timestamp without time zone\":\n return config.temporal ? plainDateTimeCode : dateCode;\n case \"date\":\n return config.temporal ? plainDateCode : dateCode;\n case \"jsonb\":\n return \"Object\";\n case \"bytea\":\n return \"Uint8Array\";\n default:\n assertNever(dbType);\n }\n}\n\nexport function merge<T>(a: T[], b: T[]): T[] {\n return [...a, ...b];\n}\n\n/** Returns true if `p` is resolved, otherwise false if it is rejected. */\nexport async function trueIfResolved(p: Promise<unknown>): Promise<boolean> {\n return p.then(\n () => true,\n () => false,\n );\n}\n\nexport function fail(message?: string): never {\n throw new Error(message || \"Failed\");\n}\n\nexport function sortKeys<T extends object>(o: T): T {\n return Object.keys(o)\n .sort()\n .reduce(\n (acc, key) => {\n const value = o[key as keyof T];\n const newValue = typeof value === \"object\" && isPlainObject(value) ? sortKeys(value as any as object) : value;\n acc[key as keyof T] = newValue as any;\n return acc;\n },\n {} as any as T,\n );\n}\n\nexport function parseOrder(order: string | undefined): { field: string; direction: \"ASC\" | \"DESC\" } | undefined {\n if (!order) {\n return undefined;\n }\n const [field, direction = \"ASC\"] = order.split(\" \");\n if (direction !== \"ASC\" && direction !== \"DESC\") {\n throw new Error(`Invalid direction: ${direction} (must be \"ASC\" or \"DESC\")`);\n }\n return { field, direction };\n}\n\nexport function q(s: string | undefined): string {\n return s === undefined ? \"undefined\" : `\"${s}\"`;\n}\n\nexport function uncapitalize(s: string): string {\n return s.charAt(0).toLowerCase() + s.slice(1);\n}\n\nfunction isIgnored(config: Config, t: Table): boolean {\n return (config.ignoredTables || [\"migrations\", \"pgmigrations\"]).includes(t.name) || !shouldIncludeSchema(config, t);\n}\n\nfunction shouldIncludeSchema(config: Config, t: Table): boolean {\n return config.schemas ? config.schemas.includes(t.schema.name) : t.schema.name === \"public\";\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,YAAY,GAAiB;CAC3C,MAAM,IAAI,MAAM,wBAAwB,CAAC;AAC3C;AAEA,SAAgB,cAAc,QAAgB,GAAmB;CAC/D,IAAI,UAAU,QAAQ,CAAC,KAAK,YAAY,QAAQ,CAAC,GAC/C,OAAO;CAKT,MAAM,cAAc,EAAE,QAAQ,KAAK,MAAM,EAAE,IAAI;CAC/C,MAAM,EAAE,eAAe,kBAAkB,mBAAmB,MAAM;CAClE,MAAM,eAAe,cAAc,MAAM,MAAM,MAAM,YAAY,SAAS,CAAC,CAAC;CAC5E,MAAM,eAAe,cAAc,MAAM,MAAM,MAAM,YAAY,SAAS,CAAC,CAAC;CAG5E,MAAM,cAAc,YAAY,SAAS,IAAI;CAC7C,IAAI,CAAC,aAAa,OAAO;CAGzB,IAAI,eAAe,CAAC,gBAAgB,CAAC,cAC/B;MAAA,CAAC,QAAQ,MAAM,CAAC,CAAC,OAAO,MAAM,YAAY,SAAS,CAAC,CAAC,GACvD,OAAO;CAAA;CAKX,IAAI,gBAAgB,CAAC,GAAG,OAAO;CAG/B,OAAO,gBAAgB,gBAAgB,CAAC,cAAc,cAAc,gBAAgB,CAAC,cAAc;AACrG;AAEA,SAAgB,gBAAgB,GAAmB;CAEjD,OAAO,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC,YAAY,WAAW;AACpD;AAEA,S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pB;;AAGA,eAAsB,eAAe,GAAuC;CAC1E,OAAO,EAAE,WACD,YACA,KACR;AACF;AAEA,SAAgB,KAAK,SAAyB;CAC5C,MAAM,IAAI,MAAM,WAAW,QAAQ;AACrC;AAEA,SAAgB,SAA2B,GAAS;CAClD,OAAO,OAAO,KAAK,CAAC,CAAC,CAClB,KAAK,CAAC,CACN,QACE,KAAK,QAAQ;EACZ,MAAM,QAAQ,EAAE;EAEhB,IAAI,OADa,OAAO,UAAU,YAAY,cAAc,KAAK,IAAI,SAAS,KAAsB,IAAI;EAExG,OAAO;CACT,GACA,CAAC,CACH;AACJ;AAEA,SAAgB,WAAW,OAAqF;CAC9G,IAAI,CAAC,OACH;CAEF,MAAM,CAAC,OAAO,YAAY,SAAS,MAAM,MAAM,GAAG;CAClD,IAAI,cAAc,SAAS,cAAc,QACvC,MAAM,IAAI,MAAM,sBAAsB,UAAU,2BAA2B;CAE7E,OAAO;EAAE;EAAO;CAAU;AAC5B;AAEA,SAAgB,EAAE,GAA+B;CAC/C,OAAO,MAAM,KAAA,IAAY,cAAc,IAAI,EAAE;AAC/C;AAEA,SAAgB,aAAa,GAAmB;CAC9C,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,EAAE,MAAM,CAAC;AAC9C;AAEA,SAAS,UAAU,QAAgB,GAAmB;CACpD,QAAQ,OAAO,iBAAiB,CAAC,cAAc,cAAc,EAAA,CAAG,SAAS,EAAE,IAAI,KAAK,CAAC,oBAAoB,QAAQ,CAAC;AACpH;AAEA,SAAS,oBAAoB,QAAgB,GAAmB;CAC9D,OAAO,OAAO,UAAU,OAAO,QAAQ,SAAS,EAAE,OAAO,IAAI,IAAI,EAAE,OAAO,SAAS;AACrF"}
@@ -0,0 +1,23 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_config = require("./config.cjs");
3
+ let fs = require("fs");
4
+ let _dprint_formatter = require("@dprint/formatter");
5
+ let _dprint_json = require("@dprint/json");
6
+ let zod = require("zod");
7
+ //#region src/write-json-schema.ts
8
+ const jsonFormatter = (0, _dprint_formatter.createFromBuffer)((0, fs.readFileSync)((0, _dprint_json.getPath)()));
9
+ async function main() {
10
+ const jsonSchema = zod.z.toJSONSchema(require_config.config, {
11
+ io: "input",
12
+ unrepresentable: "any"
13
+ });
14
+ const content = jsonFormatter.formatText({
15
+ filePath: "test.json",
16
+ fileText: JSON.stringify(jsonSchema)
17
+ });
18
+ await fs.promises.writeFile("./config-json-schema.json", content);
19
+ }
20
+ main();
21
+ //#endregion
22
+
23
+ //# sourceMappingURL=write-json-schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-json-schema.cjs","names":["createFromBuffer","readFileSync","getPath","z","config"],"sources":["../src/write-json-schema.ts"],"sourcesContent":["import { promises as fs, readFileSync } from \"fs\";\n\nimport { createFromBuffer } from \"@dprint/formatter\";\nimport { getPath } from \"@dprint/json\";\nimport { z } from \"zod\";\n\nimport { config } from \"./config.ts\";\n\nconst jsonFormatter = createFromBuffer(readFileSync(getPath()));\n\nasync function main() {\n // `io: \"input\"` since the schema validates the user-authored joist-config.json, and\n // `unrepresentable: \"any\"` to skip the `uniqueBy` transform that has no JSON Schema form.\n const jsonSchema = z.toJSONSchema(config, { io: \"input\", unrepresentable: \"any\" });\n const content = jsonFormatter.formatText({ filePath: \"test.json\", fileText: JSON.stringify(jsonSchema) });\n await fs.writeFile(\"./config-json-schema.json\", content);\n}\n\nmain();\n"],"mappings":";;;;;;;AAQA,MAAM,iBAAA,GAAgBA,kBAAAA,iBAAAA,EAAAA,GAAiBC,GAAAA,aAAAA,EAAAA,GAAaC,aAAAA,QAAAA,CAAQ,CAAC,CAAC;AAE9D,eAAe,OAAO;CAGpB,MAAM,aAAaC,IAAAA,EAAE,aAAaC,eAAAA,QAAQ;EAAE,IAAI;EAAS,iBAAiB;CAAM,CAAC;CACjF,MAAM,UAAU,cAAc,WAAW;EAAE,UAAU;EAAa,UAAU,KAAK,UAAU,UAAU;CAAE,CAAC;CACxG,MAAM,GAAA,SAAG,UAAU,6BAA6B,OAAO;AACzD;AAEA,KAAK"}
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1 @@
1
+ export {}
@@ -1,17 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const formatter_1 = require("@dprint/formatter");
4
- const json_1 = require("@dprint/json");
5
- const fs_1 = require("fs");
6
- const zod_1 = require("zod");
7
- const config_1 = require("./config");
8
- const jsonFormatter = (0, formatter_1.createFromBuffer)((0, fs_1.readFileSync)((0, json_1.getPath)()));
1
+ import { config } from "./config.js";
2
+ import { promises, readFileSync } from "fs";
3
+ import { createFromBuffer } from "@dprint/formatter";
4
+ import { getPath } from "@dprint/json";
5
+ import { z } from "zod";
6
+ //#region src/write-json-schema.ts
7
+ const jsonFormatter = createFromBuffer(readFileSync(getPath()));
9
8
  async function main() {
10
- // `io: "input"` since the schema validates the user-authored joist-config.json, and
11
- // `unrepresentable: "any"` to skip the `uniqueBy` transform that has no JSON Schema form.
12
- const jsonSchema = zod_1.z.toJSONSchema(config_1.config, { io: "input", unrepresentable: "any" });
13
- const content = jsonFormatter.formatText({ filePath: "test.json", fileText: JSON.stringify(jsonSchema) });
14
- await fs_1.promises.writeFile("./config-json-schema.json", content);
9
+ const jsonSchema = z.toJSONSchema(config, {
10
+ io: "input",
11
+ unrepresentable: "any"
12
+ });
13
+ const content = jsonFormatter.formatText({
14
+ filePath: "test.json",
15
+ fileText: JSON.stringify(jsonSchema)
16
+ });
17
+ await promises.writeFile("./config-json-schema.json", content);
15
18
  }
16
19
  main();
20
+ //#endregion
21
+ export {};
22
+
17
23
  //# sourceMappingURL=write-json-schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"write-json-schema.js","sourceRoot":"","sources":["../src/write-json-schema.ts"],"names":[],"mappings":";;AAAA,iDAAqD;AACrD,uCAAuC;AACvC,2BAAkD;AAClD,6BAAwB;AACxB,qCAAkC;AAElC,MAAM,aAAa,GAAG,IAAA,4BAAgB,EAAC,IAAA,iBAAY,EAAC,IAAA,cAAO,GAAE,CAAC,CAAC,CAAC;AAEhE,KAAK,UAAU,IAAI;IACjB,oFAAoF;IACpF,0FAA0F;IAC1F,MAAM,UAAU,GAAG,OAAC,CAAC,YAAY,CAAC,eAAM,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC;IACnF,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1G,MAAM,aAAE,CAAC,SAAS,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"write-json-schema.js","names":["fs"],"sources":["../src/write-json-schema.ts"],"sourcesContent":["import { promises as fs, readFileSync } from \"fs\";\n\nimport { createFromBuffer } from \"@dprint/formatter\";\nimport { getPath } from \"@dprint/json\";\nimport { z } from \"zod\";\n\nimport { config } from \"./config.ts\";\n\nconst jsonFormatter = createFromBuffer(readFileSync(getPath()));\n\nasync function main() {\n // `io: \"input\"` since the schema validates the user-authored joist-config.json, and\n // `unrepresentable: \"any\"` to skip the `uniqueBy` transform that has no JSON Schema form.\n const jsonSchema = z.toJSONSchema(config, { io: \"input\", unrepresentable: \"any\" });\n const content = jsonFormatter.formatText({ filePath: \"test.json\", fileText: JSON.stringify(jsonSchema) });\n await fs.writeFile(\"./config-json-schema.json\", content);\n}\n\nmain();\n"],"mappings":";;;;;;AAQA,MAAM,gBAAgB,iBAAiB,aAAa,QAAQ,CAAC,CAAC;AAE9D,eAAe,OAAO;CAGpB,MAAM,aAAa,EAAE,aAAa,QAAQ;EAAE,IAAI;EAAS,iBAAiB;CAAM,CAAC;CACjF,MAAM,UAAU,cAAc,WAAW;EAAE,UAAU;EAAa,UAAU,KAAK,UAAU,UAAU;CAAE,CAAC;CACxG,MAAMA,SAAG,UAAU,6BAA6B,OAAO;AACzD;AAEA,KAAK"}
package/package.json CHANGED
@@ -1,50 +1,70 @@
1
1
  {
2
2
  "name": "joist-codegen",
3
- "version": "2.3.0-next.6",
3
+ "version": "2.3.0-next.60",
4
4
  "license": "MIT",
5
+ "type": "module",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/joist-orm/joist-orm.git",
8
9
  "directory": "packages/codegen"
9
10
  },
10
- "main": "build/index.js",
11
- "types": "build/index.d.ts",
12
- "bin": "build/index.js",
13
- "scripts": {
14
- "format": "prettier --ignore-path ../../.prettierignore --write '{schema,migrations,src}/**/*.{ts,js,tsx,jsx,graphql}'"
11
+ "main": "build/index.cjs",
12
+ "module": "build/index.js",
13
+ "types": "build/index.d.mts",
14
+ "exports": {
15
+ ".": {
16
+ "bun": {
17
+ "types": "./build/index.d.mts",
18
+ "default": "./build/index.js"
19
+ },
20
+ "module-sync": {
21
+ "types": "./build/index.d.mts",
22
+ "default": "./build/index.js"
23
+ },
24
+ "import": {
25
+ "types": "./build/index.d.mts",
26
+ "default": "./build/index.js"
27
+ },
28
+ "require": {
29
+ "types": "./build/index.d.cts",
30
+ "default": "./build/index.cjs"
31
+ },
32
+ "default": "./build/index.js"
33
+ }
15
34
  },
35
+ "bin": "build/index.cjs",
16
36
  "files": [
17
- "build"
37
+ "build",
38
+ "skills"
18
39
  ],
19
40
  "peerDependencies": {
20
- "joist-utils": "2.3.0-next.6",
41
+ "joist-utils": "2.3.0-next.60",
21
42
  "knex": "^3.1.0",
22
- "pg": "^8.22.0"
43
+ "pg": "^8.23.0"
23
44
  },
24
45
  "dependencies": {
25
46
  "@dprint/formatter": "^0.5.1",
26
47
  "@dprint/json": "^0.21.3",
27
- "@inquirer/prompts": "^8.5.2",
48
+ "@inquirer/prompts": "^8.6.0",
28
49
  "@types/jscodeshift": "^17.3.0",
29
50
  "@types/pluralize": "^0.0.33",
30
51
  "change-case": "^4.1.2",
31
52
  "fast-glob": "^3.3.3",
32
- "jscodeshift": "^17.3.0",
53
+ "jscodeshift": "^17.4.0",
54
+ "jsonc-parser": "^3.3.1",
33
55
  "pg-structure": "^7.15.3",
34
56
  "pluralize": "^8.0.0",
35
- "prettier": "^3.8.4",
57
+ "prettier": "^3.9.6",
36
58
  "ts-poet": "^6.12.0",
37
59
  "zod": "^4.4.3"
38
60
  },
39
61
  "devDependencies": {
40
62
  "@swc/jest": "^0.2.39",
41
63
  "@types/jest": "^30.0.0",
42
- "@types/node": "^26.0.1",
64
+ "@types/node": "^26.2.0",
43
65
  "jest": "30.4.2",
44
- "prettier-plugin-organize-imports": "^4.3.0",
45
- "ts-node-dev": "^2.0.0",
46
66
  "tsconfig-paths": "^4.2.0",
47
- "tsx": "^4.22.4",
48
- "typescript": "6.0.3"
67
+ "tsx": "^4.23.12",
68
+ "typescript": "7.0.2"
49
69
  }
50
70
  }
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: entity-docs
3
+ description: Read and write the `src/entities/<Entity>.md` business-docs that sit next to each Joist entity. Use when working on ANY entity in `src/entities/` (its `.ts`, resolvers, jobs, or tests) — read the sibling `.md` first for the business rationale, worked scenarios, and gotchas the code can't show, and record any non-obvious domain knowledge you learn back into it. Also covers the codegen doc-sync: how `## Overview` and `## Fields`/`### fieldName` sections become entity JSDocs via `yarn joist-codegen`, and what belongs in field docs vs. free-form narrative.
4
+ ---
5
+
6
+ # Entity docs (`src/entities/<Entity>.md`)
7
+
8
+ Many Joist entities have a sibling Markdown doc — `src/entities/Author.ts` ↔
9
+ `src/entities/Author.md` (same basename; enums under `src/entities/enums/` too). These files hold the
10
+ **"why"** that code can't: business rationale, worked scenarios, gotchas, domain vocabulary, and
11
+ cross-entity workflows. They are written for **both humans and agents** — you are a primary audience.
12
+
13
+ Two jobs, and you should do both as a matter of course:
14
+
15
+ 1. **Read** the sibling `.md` before/while you work on an entity, to get domain context.
16
+ 2. **Write** back to it whenever you learn something useful, weird, or non-obvious.
17
+
18
+ ## 1. Read it first
19
+
20
+ Before editing an entity — its `src/entities/<Entity>.ts`, its resolvers, a job that touches it, or its
21
+ tests — open `src/entities/<Entity>.md` if one exists. It routinely explains things you would otherwise
22
+ have to reverse-engineer or would get subtly wrong:
23
+
24
+ - **Business rationale** — *why* a field/entity exists and what real-world thing it models
25
+ (e.g. `PurchaseOrder.md` on tracking "what and why" a project's cost changed).
26
+ - **Worked scenarios** — concrete `I.e.` walkthroughs with real values ("when an `Employee` is termined, the status workflow is...").
27
+ - **Gotchas & edge cases** — footguns, "this looks stale but isn't", exemptions
28
+ - **Domain vocabulary** — statuses, flags, and other "esoteric unless you know it" domain concepts
29
+
30
+ Follow the cross-links (`[Book](Book.md)`, sometimes with anchors like
31
+ `Book.md#Definitions`) into related docs. If the doc is missing or thin, that's your cue to add
32
+ to it once you've figured things out (job #2).
33
+
34
+ ## 2. How the file maps to code (the codegen doc-sync)
35
+
36
+ `joist-config.json` has `"docs": true`, so `yarn joist-codegen` keeps these `.md` files and the entity
37
+ JSDocs in sync. Understanding this is what makes your writing land in the right place.
38
+
39
+ **Only two heading shapes are parsed and synced; everything else is free-form narrative:**
40
+
41
+ | `.md` section | Syncs to | Notes |
42
+ |---|---|---|
43
+ | `## Overview` (body) | the entity **class** JSDoc | exact heading `## Overview` |
44
+ | `## Fields` → `### <fieldName>` (body) | that field/property/relation's JSDoc | `### ` heading must be the **exact member name** |
45
+ | any other `## Section` (e.g. `## Hard vs. Soft Costs`, `## DB Constraints`, mermaid) | **nothing** | free-form; lives only in the `.md`, preserved verbatim |
46
+
47
+ Synced JSDocs are tagged `@generated <Entity>.md` in the `.ts` — that tag means "this comment came from
48
+ the `.md`; edit the `.md`, not here."
49
+
50
+ **Sync is bidirectional, but the `.md` wins.** `yarn joist-codegen`:
51
+
52
+ 1. **Backfills** the `.md` from any hand-written `.ts` JSDoc that isn't in the `.md` yet (so a jsdoc you
53
+ write directly on a field gets pulled into `## Fields` for you), then
54
+ 2. **Writes the `.md` back into the `.ts`** JSDocs — so for anything already in the `.md`, the `.md` is
55
+ the source of truth and will overwrite a divergent `.ts` comment.
56
+
57
+ Net rule: **to durably document an entity or field, edit the `.md`.** Hand-editing a `@generated` JSDoc
58
+ in the `.ts` gets stomped on the next codegen.
59
+
60
+ ### Field-heading constraints (easy to get wrong)
61
+
62
+ - `### <fieldName>` must be a **single word** — the parser matches `\w+` only. `### excludeFromBudget`
63
+ works; `### is excluded`, `` ### `excludeFromBudget` ``, or `### excludeFromBudget (derived)` are **not**
64
+ recognized as field docs.
65
+ - It must be the **exact** name of a field, relation, or property on the entity, and must sit **under the
66
+ `## Fields` heading**. Any other `##` heading ends the fields section — so keep all `### fieldName`
67
+ entries together under the one `## Fields` section (conventionally at the bottom of the file).
68
+ - **Methods don't sync** — only fields/getters/properties/relations get their JSDoc updated.
69
+
70
+ ## 3. Write back what you learn
71
+
72
+ When you discover something useful/weird/non-obvious while working — record it. This is the point of the
73
+ files. Good triggers to write:
74
+
75
+ - You just figured out **why** an entity or field exists, or what it really models.
76
+ - A **non-obvious business rule**, invariant, or "this only applies to X clients" exemption.
77
+ - A **gotcha / footgun** — a value that looks stale but isn't, an ordering requirement, a special-cased
78
+ type.
79
+ - A **cross-entity interaction** or workflow that isn't visible from one file.
80
+ - **Domain vocabulary** a newcomer (human or agent) wouldn't know.
81
+ - A **worked scenario** that makes an abstract entity concrete.
82
+
83
+ **Don't** document what the code already says plainly (restating a type, signature, or an obvious
84
+ one-liner), or transient implementation detail that will rot.
85
+
86
+ **Where to put it:**
87
+
88
+ - Something specific to one field → a `### <fieldName>` block under `## Fields`. It syncs to that
89
+ member's JSDoc, so it shows on hover/`@generated` in the `.ts`.
90
+ - Broad rationale, scenarios, diagrams, cross-entity workflows, DB constraints, glossary → a free-form
91
+ `##` section (`## Overview` for the headline, or a custom section like `## Employee Onboarding Flow`).
92
+
93
+ **Style** (match the existing docs):
94
+
95
+ - Lead with business meaning and *why*, not mechanics.
96
+ - Use `I.e. ...` worked examples with concrete values.
97
+ - Cross-link related entities with relative links: `[Book](Book.md)`.
98
+ - Reference field/entity names in backticks.
99
+
100
+ ## 4. Workflow to add or update a doc
101
+
102
+ 1. Edit `src/entities/<Entity>.md` (create it if missing — basename must equal the entity, e.g.
103
+ `Author.md`). For field docs, use the exact member name as a `### ` heading under `## Fields`.
104
+ 2. Sync into the JSDocs:
105
+ ```bash
106
+ mise exec -- yarn joist-codegen
107
+ ```
108
+ (or `mise exec -- yarn codegen` to also run graphql-codegen.)
109
+ 3. Verify the `@generated <Entity>.md` JSDoc now appears on the class / field in `src/entities/<Entity>.ts`.
110
+ 4. Commit the `.md` **and** the regenerated `.ts` JSDoc changes together.
111
+
112
+ Never hand-edit a `@generated <Entity>.md` JSDoc in the `.ts` — edit the `.md` and re-run codegen. Do not
113
+ touch files under `src/entities/codegen/` (see the repo's generated-files rules).
114
+
115
+ ## Skeleton for a new doc
116
+
117
+ ```markdown
118
+ # <Entity>
119
+
120
+ ## Overview
121
+
122
+ <What this entity models and *why* it exists, in business terms. One short paragraph.>
123
+
124
+ ## <Some Business Concept> <!-- free-form: rationale, scenarios, gotchas, diagrams; NOT synced -->
125
+
126
+ <Prose, `I.e.` examples, mermaid, cross-links to [OtherEntity](OtherEntity.md).>
127
+
128
+ ## Fields <!-- each ### below syncs into that member's JSDoc -->
129
+
130
+ ### someField
131
+
132
+ <Why it exists / the non-obvious rule or gotcha. Exact field name, single word.>
133
+ ```
@@ -0,0 +1,114 @@
1
+ ---
2
+ name: joist-em-basics
3
+ description: Create, load, find, mutate, and save entities with Joist's EntityManager. Use when writing data-access or business logic in a Joist project — anything using em.create, em.load, em.find, em.flush, or walking the entity graph.
4
+ ---
5
+
6
+ <!-- Managed by joist-codegen. Do not edit by hand; re-run codegen to update. -->
7
+
8
+ # Joist EntityManager basics
9
+
10
+ The `EntityManager` (`em`) is how entities are loaded from and saved to the
11
+ database. It is a Unit of Work: each request gets its own `em`, which tracks
12
+ the entities it has loaded/created and writes them all out on `em.flush()`.
13
+
14
+ Entities are always loaded/created _through_ the `em`, never via static methods
15
+ on the class (Joist is not ActiveRecord). IDs are tagged strings like `"a:1"`.
16
+
17
+ ## Creating
18
+
19
+ `em.create` is synchronous and returns the new entity immediately:
20
+
21
+ ```ts
22
+ const author = em.create(Author, { firstName: "a1" });
23
+ // Nested/related entities can be created inline
24
+ const author = em.create(Author, { firstName: "a1", address: { street: "123 Main" } });
25
+ ```
26
+
27
+ ## Loading by id
28
+
29
+ Use tagged ids. These throw if the id does not exist (except the `IfExists`
30
+ variants):
31
+
32
+ ```ts
33
+ const a = await em.load(Author, "a:1");
34
+ const as = await em.loadAll(Author, ["a:1", "a:2"]);
35
+ const as = await em.loadAllIfExists(Author, ["a:1", "a:2"]); // skips missing ids
36
+ ```
37
+
38
+ To eagerly load relations, pass a populate hint as the 3rd argument; the
39
+ returned entity is typed as "loaded" so the relations can be read synchronously:
40
+
41
+ ```ts
42
+ const a = await em.load(Author, "a:1", { books: "reviews" });
43
+ a.books.get.flatMap((b) => b.reviews.get);
44
+ ```
45
+
46
+ ## Walking the graph
47
+
48
+ ~90% of reads are just navigating relations from an entity you already have.
49
+ These are guaranteed N+1-safe, even in a loop:
50
+
51
+ ```ts
52
+ const author = await book.author.load(); // load a single relation
53
+ const reviews = await publisher.load((p) => p.books.reviews); // lens
54
+ const loaded = await author.populate({ books: "reviews" }); // populate + .get
55
+ ```
56
+
57
+ ## Finding (filtered queries)
58
+
59
+ `em.find` issues a `SELECT` with a "join literal" of nested relations plus
60
+ inline `WHERE` conditions. It is batch/N+1-safe.
61
+
62
+ ```ts
63
+ const books = await em.find(Book, { author: { firstName: "a1" } });
64
+ const recent = await em.find(Book, { publishedAt: { gte: jan1 } });
65
+ const some = await em.find(Author, { firstName: { in: ["a1", "a2"] } });
66
+
67
+ const one = await em.findOne(Book, { title: "b1" }); // undefined if none
68
+ const one = await em.findOneOrFail(Book, { title: "b1" }); // throws if none
69
+ const one = await em.findOrCreate(Author, { email: "a@b.com" });
70
+ ```
71
+
72
+ `undefined` values are pruned (the condition and any now-unused join are
73
+ dropped), so filters compose cleanly. To filter for null, pass `null`
74
+ explicitly, e.g. `{ firstName: null }`. For `OR` / nested boolean logic, use
75
+ `alias`/`aliases` with a `conditions` argument. For aggregates or group-bys,
76
+ drop down to Knex/Kysely — Joist's `find` only returns whole entities.
77
+
78
+ ## Mutating
79
+
80
+ Assign fields directly, or use `.set` for a batch of changes:
81
+
82
+ ```ts
83
+ author.firstName = "a2";
84
+ author.set({ firstName: "a2", lastName: "b2" });
85
+ ```
86
+
87
+ For partial/RPC-style updates (treating `null` as "unset"), and for
88
+ incrementally updating children, see the `joist-upsert` skill.
89
+
90
+ ## Deleting
91
+
92
+ ```ts
93
+ const a = await em.load(Author, "a:1");
94
+ em.delete(a);
95
+ ```
96
+
97
+ ## Saving with `em.flush()`
98
+
99
+ `em.flush()` is where everything happens. It is async and:
100
+
101
+ 1. Runs lifecycle hooks and validation rules,
102
+ 2. Opens a transaction,
103
+ 3. Issues batched `INSERT`/`UPDATE`/`DELETE` (one batch per entity type),
104
+ 4. Commits.
105
+
106
+ You don't write individual SQL statements — let Joist batch them. `flush` can
107
+ be called multiple times as you do more work:
108
+
109
+ ```ts
110
+ const author = em.create(Author, { firstName: "a1" });
111
+ await em.flush();
112
+ author.firstName = "a2";
113
+ await em.flush();
114
+ ```