joist-codegen 2.4.0 → 2.5.0-next.10

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 (249) hide show
  1. package/build/EntityDbMetadata.cjs +50 -8
  2. package/build/EntityDbMetadata.cjs.map +1 -1
  3. package/build/EntityDbMetadata.d.cts +36 -28
  4. package/build/EntityDbMetadata.d.cts.map +1 -1
  5. package/build/EntityDbMetadata.d.mts +36 -28
  6. package/build/EntityDbMetadata.d.mts.map +1 -1
  7. package/build/EntityDbMetadata.js +50 -9
  8. package/build/EntityDbMetadata.js.map +1 -1
  9. package/build/_virtual/_rolldown/runtime.cjs +1 -2
  10. package/build/_virtual/_rolldown/runtime.js +1 -2
  11. package/build/assignTags.cjs +2 -3
  12. package/build/assignTags.d.cts +1 -4
  13. package/build/assignTags.d.cts.map +1 -1
  14. package/build/assignTags.d.mts +1 -4
  15. package/build/assignTags.d.mts.map +1 -1
  16. package/build/assignTags.js +2 -3
  17. package/build/codemods/Codemod.d.cts +1 -4
  18. package/build/codemods/Codemod.d.cts.map +1 -1
  19. package/build/codemods/Codemod.d.mts +1 -4
  20. package/build/codemods/Codemod.d.mts.map +1 -1
  21. package/build/codemods/JscodeshiftMod.cjs +2 -3
  22. package/build/codemods/JscodeshiftMod.d.cts +1 -4
  23. package/build/codemods/JscodeshiftMod.d.cts.map +1 -1
  24. package/build/codemods/JscodeshiftMod.d.mts +1 -4
  25. package/build/codemods/JscodeshiftMod.d.mts.map +1 -1
  26. package/build/codemods/JscodeshiftMod.js +2 -3
  27. package/build/codemods/codemod_0001-rename_has_async_property.cjs +1 -2
  28. package/build/codemods/codemod_0001-rename_has_async_property.d.cts +2 -4
  29. package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -1
  30. package/build/codemods/codemod_0001-rename_has_async_property.d.mts +2 -4
  31. package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -1
  32. package/build/codemods/codemod_0001-rename_has_async_property.js +1 -2
  33. package/build/codemods/codemod_0002-rename_async_query_fields.cjs +1 -2
  34. package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +2 -4
  35. package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -1
  36. package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +2 -4
  37. package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -1
  38. package/build/codemods/codemod_0002-rename_async_query_fields.js +1 -2
  39. package/build/codemods/codemod_0003-rename_find_paginated.cjs +1 -2
  40. package/build/codemods/codemod_0003-rename_find_paginated.d.cts +2 -4
  41. package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -1
  42. package/build/codemods/codemod_0003-rename_find_paginated.d.mts +2 -4
  43. package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -1
  44. package/build/codemods/codemod_0003-rename_find_paginated.js +1 -2
  45. package/build/codemods/index.cjs +2 -3
  46. package/build/codemods/index.d.cts +3 -6
  47. package/build/codemods/index.d.cts.map +1 -1
  48. package/build/codemods/index.d.mts +3 -6
  49. package/build/codemods/index.d.mts.map +1 -1
  50. package/build/codemods/index.js +2 -3
  51. package/build/config.cjs +11 -7
  52. package/build/config.cjs.map +1 -1
  53. package/build/config.d.cts +30 -29
  54. package/build/config.d.cts.map +1 -1
  55. package/build/config.d.mts +30 -29
  56. package/build/config.d.mts.map +1 -1
  57. package/build/config.js +11 -7
  58. package/build/config.js.map +1 -1
  59. package/build/docs/cache.cjs +1 -2
  60. package/build/docs/cache.cjs.map +1 -1
  61. package/build/docs/cache.d.cts +2 -5
  62. package/build/docs/cache.d.cts.map +1 -1
  63. package/build/docs/cache.d.mts +2 -5
  64. package/build/docs/cache.d.mts.map +1 -1
  65. package/build/docs/cache.js +1 -2
  66. package/build/docs/cache.js.map +1 -1
  67. package/build/docs/generate-metadata-docs.cjs +2 -3
  68. package/build/docs/generate-metadata-docs.d.cts +1 -4
  69. package/build/docs/generate-metadata-docs.d.cts.map +1 -1
  70. package/build/docs/generate-metadata-docs.d.mts +1 -4
  71. package/build/docs/generate-metadata-docs.d.mts.map +1 -1
  72. package/build/docs/generate-metadata-docs.js +2 -3
  73. package/build/docs/index.cjs +1 -2
  74. package/build/docs/index.d.cts +3 -5
  75. package/build/docs/index.d.cts.map +1 -1
  76. package/build/docs/index.d.mts +3 -5
  77. package/build/docs/index.d.mts.map +1 -1
  78. package/build/docs/index.js +1 -2
  79. package/build/docs/markdown.cjs +1 -2
  80. package/build/docs/markdown.d.cts +8 -10
  81. package/build/docs/markdown.d.cts.map +1 -1
  82. package/build/docs/markdown.d.mts +8 -10
  83. package/build/docs/markdown.d.mts.map +1 -1
  84. package/build/docs/markdown.js +1 -2
  85. package/build/docs/parsing.cjs +1 -2
  86. package/build/docs/parsing.d.cts +9 -11
  87. package/build/docs/parsing.d.cts.map +1 -1
  88. package/build/docs/parsing.d.mts +9 -11
  89. package/build/docs/parsing.d.mts.map +1 -1
  90. package/build/docs/parsing.js +1 -2
  91. package/build/findEntityScopes.cjs +1 -2
  92. package/build/findEntityScopes.d.cts +3 -6
  93. package/build/findEntityScopes.d.cts.map +1 -1
  94. package/build/findEntityScopes.d.mts +3 -6
  95. package/build/findEntityScopes.d.mts.map +1 -1
  96. package/build/findEntityScopes.js +1 -2
  97. package/build/foreignKeyOrdering.cjs +4 -5
  98. package/build/foreignKeyOrdering.d.cts +1 -4
  99. package/build/foreignKeyOrdering.d.cts.map +1 -1
  100. package/build/foreignKeyOrdering.d.mts +1 -4
  101. package/build/foreignKeyOrdering.d.mts.map +1 -1
  102. package/build/foreignKeyOrdering.js +4 -5
  103. package/build/generate.cjs +4 -5
  104. package/build/generate.cjs.map +1 -1
  105. package/build/generate.d.cts +3 -6
  106. package/build/generate.d.cts.map +1 -1
  107. package/build/generate.d.mts +3 -6
  108. package/build/generate.d.mts.map +1 -1
  109. package/build/generate.js +4 -5
  110. package/build/generateEntitiesFile.cjs +4 -5
  111. package/build/generateEntitiesFile.d.cts +3 -6
  112. package/build/generateEntitiesFile.d.cts.map +1 -1
  113. package/build/generateEntitiesFile.d.mts +3 -6
  114. package/build/generateEntitiesFile.d.mts.map +1 -1
  115. package/build/generateEntitiesFile.js +4 -5
  116. package/build/generateEntityCodegenFile.cjs +39 -25
  117. package/build/generateEntityCodegenFile.cjs.map +1 -1
  118. package/build/generateEntityCodegenFile.d.cts +5 -8
  119. package/build/generateEntityCodegenFile.d.cts.map +1 -1
  120. package/build/generateEntityCodegenFile.d.mts +5 -8
  121. package/build/generateEntityCodegenFile.d.mts.map +1 -1
  122. package/build/generateEntityCodegenFile.js +39 -25
  123. package/build/generateEntityCodegenFile.js.map +1 -1
  124. package/build/generateEntityFile.cjs +1 -2
  125. package/build/generateEntityFile.d.cts +1 -4
  126. package/build/generateEntityFile.d.cts.map +1 -1
  127. package/build/generateEntityFile.d.mts +1 -4
  128. package/build/generateEntityFile.d.mts.map +1 -1
  129. package/build/generateEntityFile.js +1 -2
  130. package/build/generateEntityTestFile.cjs +1 -2
  131. package/build/generateEntityTestFile.d.cts +1 -4
  132. package/build/generateEntityTestFile.d.cts.map +1 -1
  133. package/build/generateEntityTestFile.d.mts +1 -4
  134. package/build/generateEntityTestFile.d.mts.map +1 -1
  135. package/build/generateEntityTestFile.js +1 -2
  136. package/build/generateEnumFile.cjs +2 -3
  137. package/build/generateEnumFile.d.cts +1 -4
  138. package/build/generateEnumFile.d.cts.map +1 -1
  139. package/build/generateEnumFile.d.mts +1 -4
  140. package/build/generateEnumFile.d.mts.map +1 -1
  141. package/build/generateEnumFile.js +2 -3
  142. package/build/generateFactoriesFiles.cjs +2 -3
  143. package/build/generateFactoriesFiles.d.cts +1 -4
  144. package/build/generateFactoriesFiles.d.cts.map +1 -1
  145. package/build/generateFactoriesFiles.d.mts +1 -4
  146. package/build/generateFactoriesFiles.d.mts.map +1 -1
  147. package/build/generateFactoriesFiles.js +2 -3
  148. package/build/generateFlushFunction.cjs +1 -2
  149. package/build/generateFlushFunction.d.cts +3 -6
  150. package/build/generateFlushFunction.d.cts.map +1 -1
  151. package/build/generateFlushFunction.d.mts +3 -6
  152. package/build/generateFlushFunction.d.mts.map +1 -1
  153. package/build/generateFlushFunction.js +1 -2
  154. package/build/generateMetadataFile.cjs +36 -5
  155. package/build/generateMetadataFile.cjs.map +1 -1
  156. package/build/generateMetadataFile.d.cts +2 -5
  157. package/build/generateMetadataFile.d.cts.map +1 -1
  158. package/build/generateMetadataFile.d.mts +2 -5
  159. package/build/generateMetadataFile.d.mts.map +1 -1
  160. package/build/generateMetadataFile.js +37 -6
  161. package/build/generateMetadataFile.js.map +1 -1
  162. package/build/generatePgEnumFile.cjs +1 -2
  163. package/build/generatePgEnumFile.d.cts +1 -4
  164. package/build/generatePgEnumFile.d.cts.map +1 -1
  165. package/build/generatePgEnumFile.d.mts +1 -4
  166. package/build/generatePgEnumFile.d.mts.map +1 -1
  167. package/build/generatePgEnumFile.js +1 -2
  168. package/build/index.cjs +8 -9
  169. package/build/index.d.cts +5 -7
  170. package/build/index.d.cts.map +1 -1
  171. package/build/index.d.mts +5 -7
  172. package/build/index.d.mts.map +1 -1
  173. package/build/index.js +8 -9
  174. package/build/inheritance.cjs +2 -3
  175. package/build/inheritance.d.cts +3 -5
  176. package/build/inheritance.d.cts.map +1 -1
  177. package/build/inheritance.d.mts +3 -5
  178. package/build/inheritance.d.mts.map +1 -1
  179. package/build/inheritance.js +2 -3
  180. package/build/installSkills.cjs +1 -2
  181. package/build/installSkills.d.cts +1 -4
  182. package/build/installSkills.d.cts.map +1 -1
  183. package/build/installSkills.d.mts +1 -4
  184. package/build/installSkills.d.mts.map +1 -1
  185. package/build/installSkills.js +1 -2
  186. package/build/keywords.cjs +1 -2
  187. package/build/keywords.d.cts +1 -4
  188. package/build/keywords.d.cts.map +1 -1
  189. package/build/keywords.d.mts +1 -4
  190. package/build/keywords.d.mts.map +1 -1
  191. package/build/keywords.js +1 -2
  192. package/build/loadMetadata.cjs +2 -3
  193. package/build/loadMetadata.d.cts +8 -11
  194. package/build/loadMetadata.d.cts.map +1 -1
  195. package/build/loadMetadata.d.mts +8 -11
  196. package/build/loadMetadata.d.mts.map +1 -1
  197. package/build/loadMetadata.js +2 -3
  198. package/build/logger.cjs +1 -2
  199. package/build/logger.d.cts +3 -6
  200. package/build/logger.d.cts.map +1 -1
  201. package/build/logger.d.mts +3 -6
  202. package/build/logger.d.mts.map +1 -1
  203. package/build/logger.js +1 -2
  204. package/build/pgMetadata.cjs +1 -2
  205. package/build/pgMetadata.d.cts +13 -16
  206. package/build/pgMetadata.d.cts.map +1 -1
  207. package/build/pgMetadata.d.mts +13 -16
  208. package/build/pgMetadata.d.mts.map +1 -1
  209. package/build/pgMetadata.js +1 -2
  210. package/build/scanEntityFiles.cjs +7 -3
  211. package/build/scanEntityFiles.cjs.map +1 -1
  212. package/build/scanEntityFiles.d.cts +2 -5
  213. package/build/scanEntityFiles.d.cts.map +1 -1
  214. package/build/scanEntityFiles.d.mts +2 -5
  215. package/build/scanEntityFiles.d.mts.map +1 -1
  216. package/build/scanEntityFiles.js +7 -3
  217. package/build/scanEntityFiles.js.map +1 -1
  218. package/build/sortForeignKeys.cjs +1 -2
  219. package/build/sortForeignKeys.d.cts +1 -4
  220. package/build/sortForeignKeys.d.cts.map +1 -1
  221. package/build/sortForeignKeys.d.mts +1 -4
  222. package/build/sortForeignKeys.d.mts.map +1 -1
  223. package/build/sortForeignKeys.js +1 -2
  224. package/build/symbols.cjs +3 -2
  225. package/build/symbols.cjs.map +1 -1
  226. package/build/symbols.d.cts +117 -119
  227. package/build/symbols.d.cts.map +1 -1
  228. package/build/symbols.d.mts +117 -119
  229. package/build/symbols.d.mts.map +1 -1
  230. package/build/symbols.js +3 -3
  231. package/build/symbols.js.map +1 -1
  232. package/build/tsdoc.cjs +1 -2
  233. package/build/tsdoc.d.cts +1 -4
  234. package/build/tsdoc.d.cts.map +1 -1
  235. package/build/tsdoc.d.mts +1 -4
  236. package/build/tsdoc.d.mts.map +1 -1
  237. package/build/tsdoc.js +1 -2
  238. package/build/utils.cjs +3 -3
  239. package/build/utils.cjs.map +1 -1
  240. package/build/utils.d.cts +22 -25
  241. package/build/utils.d.cts.map +1 -1
  242. package/build/utils.d.mts +22 -25
  243. package/build/utils.d.mts.map +1 -1
  244. package/build/utils.js +3 -3
  245. package/build/utils.js.map +1 -1
  246. package/build/write-json-schema.cjs +1 -2
  247. package/build/write-json-schema.js +1 -2
  248. package/package.json +10 -10
  249. package/skills/joist-test-factories/SKILL.md +93 -6
@@ -1,31 +1,28 @@
1
1
  import { Config } from "./config.mjs";
2
- import { Db, Table } from "./pgMetadata.mjs";
3
2
  import "./index.mjs";
3
+ import { Db, Table } from "./pgMetadata.mjs";
4
4
  import { PrimitiveField } from "./EntityDbMetadata.mjs";
5
5
  import { Client } from "pg";
6
- //#region src/loadMetadata.d.ts
7
6
  /** A map from Enum table name to the rows currently in the table. */
8
- type EnumTableData = {
7
+ export type EnumTableData = {
9
8
  table: Table;
10
9
  idType: "integer" | "uuid";
11
10
  name: string;
12
11
  rows: EnumRow[];
13
12
  extraPrimitives: PrimitiveField[];
14
13
  };
15
- type PgEnumData = {
14
+ export type PgEnumData = {
16
15
  name: string;
17
16
  values: string[];
18
17
  };
19
- type EnumMetadata = Record<string, EnumTableData>;
20
- type PgEnumMetadata = Record<string, PgEnumData>;
21
- type EnumRow = {
18
+ export type EnumMetadata = Record<string, EnumTableData>;
19
+ export type PgEnumMetadata = Record<string, PgEnumData>;
20
+ export type EnumRow = {
22
21
  id: number;
23
22
  code: string;
24
23
  name: string;
25
24
  [key: string]: any;
26
25
  };
27
- declare function loadEnumMetadata(db: Db, client: Client, config: Config): Promise<EnumMetadata>;
28
- declare function loadPgEnumMetadata(db: Db, client: Client, config: Config): Promise<PgEnumMetadata>;
29
- //#endregion
30
- export { EnumMetadata, EnumRow, EnumTableData, PgEnumData, PgEnumMetadata, loadEnumMetadata, loadPgEnumMetadata };
26
+ export declare function loadEnumMetadata(db: Db, client: Client, config: Config): Promise<EnumMetadata>;
27
+ export declare function loadPgEnumMetadata(db: Db, client: Client, config: Config): Promise<PgEnumMetadata>;
31
28
  //# sourceMappingURL=loadMetadata.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loadMetadata.d.mts","names":[],"sources":["../src/loadMetadata.ts"],"mappings":";;;;;;;KAQY;EACV,OAAO;EACP;EAEA;EACA,MAAM;EACN,iBAAiB;;KAGP;EACV;EACA;;KAGU,eAAe,eAAe;KAC9B,iBAAiB,eAAe;KAEhC;EAAY;EAAY;EAAc;GAAe;;iBAE3C,iBAAiB,IAAI,IAAI,QAAQ,QAAQ,QAAQ,SAAS,QAAQ;iBAwBlE,mBAAmB,IAAI,IAAI,QAAQ,QAAQ,QAAQ,SAAS,QAAQ"}
1
+ {"version":3,"file":"loadMetadata.d.mts","names":[],"sources":["../src/loadMetadata.ts"],"mappings":";;;;;;YAQY;EACV,OAAO;EACP;EAEA;EACA,MAAM;EACN,iBAAiB;;YAGP;EACV;EACA;;YAGU,eAAe,eAAe;YAC9B,iBAAiB,eAAe;YAEhC;EAAY;EAAY;EAAc;GAAe;;wBAE3C,iBAAiB,IAAI,IAAI,QAAQ,QAAQ,QAAQ,SAAS,QAAQ;wBAwBlE,mBAAmB,IAAI,IAAI,QAAQ,QAAQ,QAAQ,SAAS,QAAQ"}
@@ -1,10 +1,10 @@
1
+ import "./index.js";
1
2
  import { EnumType } from "./pgMetadata.js";
2
3
  import { isEnumTable } from "./utils.js";
3
- import "./index.js";
4
4
  import { EntityDbMetadata } from "./EntityDbMetadata.js";
5
5
  import { pascalCase } from "change-case";
6
6
  import "pg";
7
- //#region src/loadMetadata.ts
7
+ // src/loadMetadata.ts
8
8
  async function loadEnumMetadata(db, client, config) {
9
9
  const promises = db.tables.filter((t) => isEnumTable(config, t)).map(async (table) => {
10
10
  const rows = (await client.query(`SELECT * FROM ${table.name} ORDER BY id`)).rows.map((row) => row);
@@ -31,7 +31,6 @@ async function loadPgEnumMetadata(db, client, config) {
31
31
  return all;
32
32
  }, {});
33
33
  }
34
- //#endregion
35
34
  export { loadEnumMetadata, loadPgEnumMetadata };
36
35
 
37
36
  //# sourceMappingURL=loadMetadata.js.map
package/build/logger.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region src/logger.ts
2
+ // src/logger.ts
3
3
  const LOG_LEVELS = {
4
4
  warn: 4,
5
5
  error: 5
@@ -15,7 +15,6 @@ const logger = {
15
15
  console.error("ERROR:", ...args);
16
16
  }
17
17
  };
18
- //#endregion
19
18
  exports.LOG_LEVELS = LOG_LEVELS;
20
19
  exports.logger = logger;
21
20
  Object.defineProperty(exports, "loggerMaxWarningLevelHit", {
@@ -1,13 +1,10 @@
1
- //#region src/logger.d.ts
2
- declare const LOG_LEVELS: {
1
+ export declare const LOG_LEVELS: {
3
2
  warn: number;
4
3
  error: number;
5
4
  };
6
- declare let loggerMaxWarningLevelHit: number;
7
- declare const logger: {
5
+ export declare let loggerMaxWarningLevelHit: number;
6
+ export declare const logger: {
8
7
  warn(...args: Parameters<(typeof console)["warn"]>): void;
9
8
  error(...args: Parameters<(typeof console)["error"]>): void;
10
9
  };
11
- //#endregion
12
- export { LOG_LEVELS, logger, loggerMaxWarningLevelHit };
13
10
  //# sourceMappingURL=logger.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"mappings":";cAAa;EACX;EACA;;YAGS;cAEE;EACX,QAAI,MAAU,mBAAmB;EAIjC,SAAK,MAAU,mBAAmB"}
1
+ {"version":3,"file":"logger.d.cts","names":[],"sources":["../src/logger.ts"],"mappings":"A,qBAAa;EACX;EACA;;mBAGS;qBAEE;EACX,QAAI,MAAU,mBAAmB;EAIjC,SAAK,MAAU,mBAAmB"}
@@ -1,13 +1,10 @@
1
- //#region src/logger.d.ts
2
- declare const LOG_LEVELS: {
1
+ export declare const LOG_LEVELS: {
3
2
  warn: number;
4
3
  error: number;
5
4
  };
6
- declare let loggerMaxWarningLevelHit: number;
7
- declare const logger: {
5
+ export declare let loggerMaxWarningLevelHit: number;
6
+ export declare const logger: {
8
7
  warn(...args: Parameters<(typeof console)["warn"]>): void;
9
8
  error(...args: Parameters<(typeof console)["error"]>): void;
10
9
  };
11
- //#endregion
12
- export { LOG_LEVELS, logger, loggerMaxWarningLevelHit };
13
10
  //# sourceMappingURL=logger.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.mts","names":[],"sources":["../src/logger.ts"],"mappings":";cAAa;EACX;EACA;;YAGS;cAEE;EACX,QAAI,MAAU,mBAAmB;EAIjC,SAAK,MAAU,mBAAmB"}
1
+ {"version":3,"file":"logger.d.mts","names":[],"sources":["../src/logger.ts"],"mappings":"A,qBAAa;EACX;EACA;;mBAGS;qBAEE;EACX,QAAI,MAAU,mBAAmB;EAIjC,SAAK,MAAU,mBAAmB"}
package/build/logger.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/logger.ts
1
+ // src/logger.ts
2
2
  const LOG_LEVELS = {
3
3
  warn: 4,
4
4
  error: 5
@@ -14,7 +14,6 @@ const logger = {
14
14
  console.error("ERROR:", ...args);
15
15
  }
16
16
  };
17
- //#endregion
18
17
  export { LOG_LEVELS, logger, loggerMaxWarningLevelHit };
19
18
 
20
19
  //# sourceMappingURL=logger.js.map
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
3
3
  let pluralize = require("pluralize");
4
4
  pluralize = require_runtime.__toESM(pluralize, 1);
5
- //#region src/pgMetadata.ts
5
+ // src/pgMetadata.ts
6
6
  /** The small part of PostgreSQL's catalog model used by Joist codegen. */
7
7
  var Items = class extends Array {
8
8
  byName;
@@ -317,7 +317,6 @@ function deleteAction(code) {
317
317
  function compareNames(a, b) {
318
318
  return a < b ? -1 : a > b ? 1 : 0;
319
319
  }
320
- //#endregion
321
320
  exports.Column = Column;
322
321
  exports.EnumType = EnumType;
323
322
  exports.ForeignKey = ForeignKey;
@@ -1,7 +1,6 @@
1
1
  import { Client } from "pg";
2
- //#region src/pgMetadata.d.ts
3
2
  /** The small part of PostgreSQL's catalog model used by Joist codegen. */
4
- declare class Items<T extends {
3
+ export declare class Items<T extends {
5
4
  name: string;
6
5
  }> extends Array<T> {
7
6
  private byName?;
@@ -10,17 +9,17 @@ declare class Items<T extends {
10
9
  /** Keep the name index current if more catalog rows arrive after a lookup. */
11
10
  push(...items: T[]): number;
12
11
  }
13
- type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
14
- type JSONData = string | number | boolean | null | JSONData[] | {
12
+ export type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
13
+ export type JSONData = string | number | boolean | null | JSONData[] | {
15
14
  [key: string]: JSONData;
16
15
  };
17
- declare class EnumType {
16
+ export declare class EnumType {
18
17
  name: string;
19
18
  values: string[];
20
19
  readonly shortName?: string;
21
20
  constructor(name: string, values: string[]);
22
21
  }
23
- declare class Column {
22
+ export declare class Column {
24
23
  name: string;
25
24
  type: {
26
25
  name: string;
@@ -42,14 +41,14 @@ declare class Column {
42
41
  get default(): string | null;
43
42
  get commentData(): JSONData | undefined;
44
43
  }
45
- declare class Index {
44
+ export declare class Index {
46
45
  name: string;
47
46
  columns: Column[];
48
47
  isUnique: boolean;
49
48
  isPartial: boolean;
50
49
  constructor(name: string, columns: Column[], isUnique: boolean, isPartial: boolean);
51
50
  }
52
- declare class ForeignKey {
51
+ export declare class ForeignKey {
53
52
  name: string;
54
53
  table: Table;
55
54
  referencedTable: Table;
@@ -59,7 +58,7 @@ declare class ForeignKey {
59
58
  onDelete: Action;
60
59
  constructor(name: string, table: Table, referencedTable: Table, columns: Column[], isDeferred: boolean, isDeferrable: boolean, onDelete: Action);
61
60
  }
62
- declare class M2ORelation {
61
+ export declare class M2ORelation {
63
62
  foreignKey: ForeignKey;
64
63
  readonly type = "m2o";
65
64
  constructor(foreignKey: ForeignKey);
@@ -68,7 +67,7 @@ declare class M2ORelation {
68
67
  /** Uses the old short relation name so M2O metadata keeps its factory evaluation order. */
69
68
  get name(): string;
70
69
  }
71
- declare class O2MRelation {
70
+ export declare class O2MRelation {
72
71
  foreignKey: ForeignKey;
73
72
  readonly type = "o2m";
74
73
  constructor(foreignKey: ForeignKey);
@@ -77,7 +76,7 @@ declare class O2MRelation {
77
76
  /** Keeps inverse relations in the same short-name order as pg-structure. */
78
77
  get name(): string;
79
78
  }
80
- declare class M2MRelation {
79
+ export declare class M2MRelation {
81
80
  foreignKey: ForeignKey;
82
81
  targetForeignKey: ForeignKey;
83
82
  readonly type = "m2m";
@@ -88,7 +87,7 @@ declare class M2MRelation {
88
87
  /** Adds the join-table qualifier when more than one join path reaches the same target. */
89
88
  get name(): string;
90
89
  }
91
- declare class Table {
90
+ export declare class Table {
92
91
  name: string;
93
92
  schema: {
94
93
  name: string;
@@ -111,7 +110,7 @@ declare class Table {
111
110
  get o2mRelations(): O2MRelation[];
112
111
  get m2mRelations(): M2MRelation[];
113
112
  }
114
- type Db = {
113
+ export type Db = {
115
114
  tables: Items<Table>;
116
115
  types: EnumType[];
117
116
  };
@@ -122,7 +121,5 @@ type Db = {
122
121
  * objects used by entity fields. For example, books.author_id and authors.id are joined through
123
122
  * the foreign key, while a trigger calling cyanaudit in another schema is irrelevant to codegen.
124
123
  */
125
- declare function loadPgMetadata(client: Client): Promise<Db>;
126
- //#endregion
127
- export { Action, Column, Db, EnumType, ForeignKey, Index, Items, JSONData, M2MRelation, M2ORelation, O2MRelation, Table, loadPgMetadata };
124
+ export declare function loadPgMetadata(client: Client): Promise<Db>;
128
125
  //# sourceMappingURL=pgMetadata.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pgMetadata.d.cts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;;cAIa,MAAM;EAAY;WAAwB,MAAM;UACnD;;EAGR,IAAI,eAAe;;EAUnB,QAAQ,OAAO;;KAOL;KACA,8CAA8C;GAAgB,cAAc;;cAE3E;EAGF;EACA;WAHA;EACT,YACS,cACA;;cAIE;EAMF;EACA;IAAQ;IAAc;MAAuB;EAC7C;EACA;EACA;EACA;EACA;WAXA,aAAa;WACb,eAAe;EACxB;EAEA,YACS,cACA;IAAQ;IAAc;MAAuB,UAC7C,kBACA,6BACA,sBACA,wBACA;MAGL;MAIA;MAIA,eAAe;;cAMR;EAEF;EACA,SAAS;EACT;EACA;EAJT,YACS,cACA,SAAS,UACT,mBACA;;cAIE;EAEF;EACA,OAAO;EACP,iBAAiB;EACjB,SAAS;EACT;EACA;EACA,UAAU;EAPnB,YACS,cACA,OAAO,OACP,iBAAiB,OACjB,SAAS,UACT,qBACA,uBACA,UAAU;;cAIR;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;cAWO;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;cAiBO;EAIF,YAAY;EACZ,kBAAkB;WAJlB;EAET,YACS,YAAY,YACZ,kBAAkB;MAGvB,eAAe;MAIf,eAAe;MAIf,aAAa;;MAKb;;cAmBO;EASF;EACA;IAAU;;WATV,SAAO,MAAA;WACP,SAAO,MAAA;WACP,aAAa;WACb,mBAAmB;WACnB;IAAqB,SAAS;IAAU,OAAO;;EACxD;IAAe,SAAS;;EAExB,YACS,cACA;IAAU;;MAGf,gBAAgB;MAIhB,gBAAgB;MAMhB,gBAAgB;;KAOV;EAAO,QAAQ,MAAM;EAAQ,OAAO;;;;;;;;;iBAS1B,eAAe,QAAQ,SAAS,QAAQ"}
1
+ {"version":3,"file":"pgMetadata.d.cts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;qBAIa,MAAM;EAAY;WAAwB,MAAM;UACnD;;EAGR,IAAI,eAAe;;EAUnB,QAAQ,OAAO;;YAOL;YACA,8CAA8C;GAAgB,cAAc;;qBAE3E;EAGF;EACA;WAHA;EACT,YACS,cACA;;qBAIE;EAMF;EACA;IAAQ;IAAc;MAAuB;EAC7C;EACA;EACA;EACA;EACA;WAXA,aAAa;WACb,eAAe;EACxB;EAEA,YACS,cACA;IAAQ;IAAc;MAAuB,UAC7C,kBACA,6BACA,sBACA,wBACA;MAGL;MAIA;MAIA,eAAe;;qBAMR;EAEF;EACA,SAAS;EACT;EACA;EAJT,YACS,cACA,SAAS,UACT,mBACA;;qBAIE;EAEF;EACA,OAAO;EACP,iBAAiB;EACjB,SAAS;EACT;EACA;EACA,UAAU;EAPnB,YACS,cACA,OAAO,OACP,iBAAiB,OACjB,SAAS,UACT,qBACA,uBACA,UAAU;;qBAIR;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAWO;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAiBO;EAIF,YAAY;EACZ,kBAAkB;WAJlB;EAET,YACS,YAAY,YACZ,kBAAkB;MAGvB,eAAe;MAIf,eAAe;MAIf,aAAa;;MAKb;;qBAmBO;EASF;EACA;IAAU;;WATV,SAAO,MAAA;WACP,SAAO,MAAA;WACP,aAAa;WACb,mBAAmB;WACnB;IAAqB,SAAS;IAAU,OAAO;;EACxD;IAAe,SAAS;;EAExB,YACS,cACA;IAAU;;MAGf,gBAAgB;MAIhB,gBAAgB;MAMhB,gBAAgB;;YAOV;EAAO,QAAQ,MAAM;EAAQ,OAAO;;;;;;;;;wBAS1B,eAAe,QAAQ,SAAS,QAAQ"}
@@ -1,7 +1,6 @@
1
1
  import { Client } from "pg";
2
- //#region src/pgMetadata.d.ts
3
2
  /** The small part of PostgreSQL's catalog model used by Joist codegen. */
4
- declare class Items<T extends {
3
+ export declare class Items<T extends {
5
4
  name: string;
6
5
  }> extends Array<T> {
7
6
  private byName?;
@@ -10,17 +9,17 @@ declare class Items<T extends {
10
9
  /** Keep the name index current if more catalog rows arrive after a lookup. */
11
10
  push(...items: T[]): number;
12
11
  }
13
- type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
14
- type JSONData = string | number | boolean | null | JSONData[] | {
12
+ export type Action = "NO ACTION" | "RESTRICT" | "CASCADE" | "SET NULL" | "SET DEFAULT";
13
+ export type JSONData = string | number | boolean | null | JSONData[] | {
15
14
  [key: string]: JSONData;
16
15
  };
17
- declare class EnumType {
16
+ export declare class EnumType {
18
17
  name: string;
19
18
  values: string[];
20
19
  readonly shortName?: string;
21
20
  constructor(name: string, values: string[]);
22
21
  }
23
- declare class Column {
22
+ export declare class Column {
24
23
  name: string;
25
24
  type: {
26
25
  name: string;
@@ -42,14 +41,14 @@ declare class Column {
42
41
  get default(): string | null;
43
42
  get commentData(): JSONData | undefined;
44
43
  }
45
- declare class Index {
44
+ export declare class Index {
46
45
  name: string;
47
46
  columns: Column[];
48
47
  isUnique: boolean;
49
48
  isPartial: boolean;
50
49
  constructor(name: string, columns: Column[], isUnique: boolean, isPartial: boolean);
51
50
  }
52
- declare class ForeignKey {
51
+ export declare class ForeignKey {
53
52
  name: string;
54
53
  table: Table;
55
54
  referencedTable: Table;
@@ -59,7 +58,7 @@ declare class ForeignKey {
59
58
  onDelete: Action;
60
59
  constructor(name: string, table: Table, referencedTable: Table, columns: Column[], isDeferred: boolean, isDeferrable: boolean, onDelete: Action);
61
60
  }
62
- declare class M2ORelation {
61
+ export declare class M2ORelation {
63
62
  foreignKey: ForeignKey;
64
63
  readonly type = "m2o";
65
64
  constructor(foreignKey: ForeignKey);
@@ -68,7 +67,7 @@ declare class M2ORelation {
68
67
  /** Uses the old short relation name so M2O metadata keeps its factory evaluation order. */
69
68
  get name(): string;
70
69
  }
71
- declare class O2MRelation {
70
+ export declare class O2MRelation {
72
71
  foreignKey: ForeignKey;
73
72
  readonly type = "o2m";
74
73
  constructor(foreignKey: ForeignKey);
@@ -77,7 +76,7 @@ declare class O2MRelation {
77
76
  /** Keeps inverse relations in the same short-name order as pg-structure. */
78
77
  get name(): string;
79
78
  }
80
- declare class M2MRelation {
79
+ export declare class M2MRelation {
81
80
  foreignKey: ForeignKey;
82
81
  targetForeignKey: ForeignKey;
83
82
  readonly type = "m2m";
@@ -88,7 +87,7 @@ declare class M2MRelation {
88
87
  /** Adds the join-table qualifier when more than one join path reaches the same target. */
89
88
  get name(): string;
90
89
  }
91
- declare class Table {
90
+ export declare class Table {
92
91
  name: string;
93
92
  schema: {
94
93
  name: string;
@@ -111,7 +110,7 @@ declare class Table {
111
110
  get o2mRelations(): O2MRelation[];
112
111
  get m2mRelations(): M2MRelation[];
113
112
  }
114
- type Db = {
113
+ export type Db = {
115
114
  tables: Items<Table>;
116
115
  types: EnumType[];
117
116
  };
@@ -122,7 +121,5 @@ type Db = {
122
121
  * objects used by entity fields. For example, books.author_id and authors.id are joined through
123
122
  * the foreign key, while a trigger calling cyanaudit in another schema is irrelevant to codegen.
124
123
  */
125
- declare function loadPgMetadata(client: Client): Promise<Db>;
126
- //#endregion
127
- export { Action, Column, Db, EnumType, ForeignKey, Index, Items, JSONData, M2MRelation, M2ORelation, O2MRelation, Table, loadPgMetadata };
124
+ export declare function loadPgMetadata(client: Client): Promise<Db>;
128
125
  //# sourceMappingURL=pgMetadata.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pgMetadata.d.mts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;;cAIa,MAAM;EAAY;WAAwB,MAAM;UACnD;;EAGR,IAAI,eAAe;;EAUnB,QAAQ,OAAO;;KAOL;KACA,8CAA8C;GAAgB,cAAc;;cAE3E;EAGF;EACA;WAHA;EACT,YACS,cACA;;cAIE;EAMF;EACA;IAAQ;IAAc;MAAuB;EAC7C;EACA;EACA;EACA;EACA;WAXA,aAAa;WACb,eAAe;EACxB;EAEA,YACS,cACA;IAAQ;IAAc;MAAuB,UAC7C,kBACA,6BACA,sBACA,wBACA;MAGL;MAIA;MAIA,eAAe;;cAMR;EAEF;EACA,SAAS;EACT;EACA;EAJT,YACS,cACA,SAAS,UACT,mBACA;;cAIE;EAEF;EACA,OAAO;EACP,iBAAiB;EACjB,SAAS;EACT;EACA;EACA,UAAU;EAPnB,YACS,cACA,OAAO,OACP,iBAAiB,OACjB,SAAS,UACT,qBACA,uBACA,UAAU;;cAIR;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;cAWO;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;cAiBO;EAIF,YAAY;EACZ,kBAAkB;WAJlB;EAET,YACS,YAAY,YACZ,kBAAkB;MAGvB,eAAe;MAIf,eAAe;MAIf,aAAa;;MAKb;;cAmBO;EASF;EACA;IAAU;;WATV,SAAO,MAAA;WACP,SAAO,MAAA;WACP,aAAa;WACb,mBAAmB;WACnB;IAAqB,SAAS;IAAU,OAAO;;EACxD;IAAe,SAAS;;EAExB,YACS,cACA;IAAU;;MAGf,gBAAgB;MAIhB,gBAAgB;MAMhB,gBAAgB;;KAOV;EAAO,QAAQ,MAAM;EAAQ,OAAO;;;;;;;;;iBAS1B,eAAe,QAAQ,SAAS,QAAQ"}
1
+ {"version":3,"file":"pgMetadata.d.mts","names":[],"sources":["../src/pgMetadata.ts"],"mappings":";;qBAIa,MAAM;EAAY;WAAwB,MAAM;UACnD;;EAGR,IAAI,eAAe;;EAUnB,QAAQ,OAAO;;YAOL;YACA,8CAA8C;GAAgB,cAAc;;qBAE3E;EAGF;EACA;WAHA;EACT,YACS,cACA;;qBAIE;EAMF;EACA;IAAQ;IAAc;MAAuB;EAC7C;EACA;EACA;EACA;EACA;WAXA,aAAa;WACb,eAAe;EACxB;EAEA,YACS,cACA;IAAQ;IAAc;MAAuB,UAC7C,kBACA,6BACA,sBACA,wBACA;MAGL;MAIA;MAIA,eAAe;;qBAMR;EAEF;EACA,SAAS;EACT;EACA;EAJT,YACS,cACA,SAAS,UACT,mBACA;;qBAIE;EAEF;EACA,OAAO;EACP,iBAAiB;EACjB,SAAS;EACT;EACA;EACA,UAAU;EAPnB,YACS,cACA,OAAO,OACP,iBAAiB,OACjB,SAAS,UACT,qBACA,uBACA,UAAU;;qBAIR;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAWO;EAGQ,YAAY;WAFtB;EAET,YAAmB,YAAY;MAE3B,eAAe;MAIf,eAAe;;MAKf;;qBAiBO;EAIF,YAAY;EACZ,kBAAkB;WAJlB;EAET,YACS,YAAY,YACZ,kBAAkB;MAGvB,eAAe;MAIf,eAAe;MAIf,aAAa;;MAKb;;qBAmBO;EASF;EACA;IAAU;;WATV,SAAO,MAAA;WACP,SAAO,MAAA;WACP,aAAa;WACb,mBAAmB;WACnB;IAAqB,SAAS;IAAU,OAAO;;EACxD;IAAe,SAAS;;EAExB,YACS,cACA;IAAU;;MAGf,gBAAgB;MAIhB,gBAAgB;MAMhB,gBAAgB;;YAOV;EAAO,QAAQ,MAAM;EAAQ,OAAO;;;;;;;;;wBAS1B,eAAe,QAAQ,SAAS,QAAQ"}
@@ -1,5 +1,5 @@
1
1
  import pluralize from "pluralize";
2
- //#region src/pgMetadata.ts
2
+ // src/pgMetadata.ts
3
3
  /** The small part of PostgreSQL's catalog model used by Joist codegen. */
4
4
  var Items = class extends Array {
5
5
  byName;
@@ -314,7 +314,6 @@ function deleteAction(code) {
314
314
  function compareNames(a, b) {
315
315
  return a < b ? -1 : a > b ? 1 : 0;
316
316
  }
317
- //#endregion
318
317
  export { Column, EnumType, ForeignKey, Index, Items, M2MRelation, M2ORelation, O2MRelation, Table, loadPgMetadata };
319
318
 
320
319
  //# sourceMappingURL=pgMetadata.js.map
@@ -3,9 +3,10 @@ require("./config.cjs");
3
3
  require("./EntityDbMetadata.cjs");
4
4
  let path = require("path");
5
5
  let fs_promises = require("fs/promises");
6
- //#region src/scanEntityFiles.ts
6
+ // src/scanEntityFiles.ts
7
7
  const regex = /config\.setDefault\([\s\n]*["'](\w+)["']/g;
8
- /** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */
8
+ const transitionsRegex = /config\.(?:setTransitions|addTransitionRule|addTransitionReaction)\(\s*(?:(?:["'][^"']*["']|\w+)\s*,\s*(?=["']))?["'](\w+)["']/g;
9
+ /** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
9
10
  async function scanEntityFiles(config, dbMeta) {
10
11
  await Promise.all(dbMeta.entities.map(async (entity) => {
11
12
  try {
@@ -15,6 +16,10 @@ async function scanEntityFiles(config, dbMeta) {
15
16
  const field = defaultableFields.find((f) => f.fieldName === match[1]);
16
17
  if (field) field.hasConfigDefault = true;
17
18
  }
19
+ for (const match of tsCode.matchAll(transitionsRegex)) {
20
+ const field = defaultableFields.find((f) => f.fieldName === match[1]);
21
+ if (field?.kind === "enum") field.hasTransitions = true;
22
+ }
18
23
  } catch (e) {}
19
24
  }));
20
25
  }
@@ -40,7 +45,6 @@ function recursiveDefaultableFields(dbMeta, entity) {
40
45
  ...entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []
41
46
  ];
42
47
  }
43
- //#endregion
44
48
  exports.scanEntityFiles = scanEntityFiles;
45
49
 
46
50
  //# sourceMappingURL=scanEntityFiles.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"scanEntityFiles.cjs","names":["readFile","join"],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;;AAeA,MAAM,QAAQ;;AAGd,eAAsB,gBAAgB,QAAgB,QAAmC;CACvF,MAAM,QAAQ,IACZ,OAAO,SAAS,IAAI,OAAO,WAAW;EACpC,IAAI;GAEF,MAAM,UAAU,OAAA,GAAMA,YAAAA,SAAAA,EAAAA,GAASC,KAAAA,KAAAA,CAAK,OAAO,mBAAmB,GAAG,OAAO,KAAK,IAAI,CAAC,EAAA,CAAG,SAAS;GAC9F,MAAM,oBAAoB,2BAA2B,QAAQ,MAAM;GACnE,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;IAC1C,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OACF,MAAM,mBAAmB;GAE7B;EACF,SAAS,GAAG,CAEZ;CACF,CAAC,CACH;AACF;;;;;;;;;;;;AAaA,SAAS,2BACP,QACA,QACqF;CACrF,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAI,OAAO,gBAAgB,2BAA2B,QAAQ,OAAO,eAAe,OAAO,cAAc,IAAI,CAAC;CAChH;AACF"}
1
+ {"version":3,"file":"scanEntityFiles.cjs","names":["readFile","join"],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n// Any transition method marks the field; addTransitionReaction may have a name before the field argument.\nconst transitionsRegex =\n /config\\.(?:setTransitions|addTransitionRule|addTransitionReaction)\\(\\s*(?:(?:[\"'][^\"']*[\"']|\\w+)\\s*,\\s*(?=[\"']))?[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n // Transition fields get `withStatus` factory opts and accessor names, i.e. `Draft`\n for (const match of tsCode.matchAll(transitionsRegex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field?.kind === \"enum\") {\n field.hasTransitions = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;;AAeA,MAAM,QAAQ;AAEd,MAAM,mBACJ;;AAGF,eAAsB,gBAAgB,QAAgB,QAAmC;CACvF,MAAM,QAAQ,IACZ,OAAO,SAAS,IAAI,OAAO,WAAW;EACpC,IAAI;GAEF,MAAM,UAAU,OAAA,GAAMA,YAAAA,SAAAA,EAAAA,GAASC,KAAAA,KAAAA,CAAK,OAAO,mBAAmB,GAAG,OAAO,KAAK,IAAI,CAAC,EAAA,CAAG,SAAS;GAC9F,MAAM,oBAAoB,2BAA2B,QAAQ,MAAM;GACnE,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;IAC1C,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OACF,MAAM,mBAAmB;GAE7B;GAEA,KAAK,MAAM,SAAS,OAAO,SAAS,gBAAgB,GAAG;IACrD,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OAAO,SAAS,QAClB,MAAM,iBAAiB;GAE3B;EACF,SAAS,GAAG,CAEZ;CACF,CAAC,CACH;AACF;;;;;;;;;;;;AAaA,SAAS,2BACP,QACA,QACqF;CACrF,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAI,OAAO,gBAAgB,2BAA2B,QAAQ,OAAO,eAAe,OAAO,cAAc,IAAI,CAAC;CAChH;AACF"}
@@ -1,8 +1,5 @@
1
1
  import { Config } from "./config.cjs";
2
2
  import { DbMetadata } from "./EntityDbMetadata.cjs";
3
- //#region src/scanEntityFiles.d.ts
4
- /** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */
5
- declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
6
- //#endregion
7
- export { scanEntityFiles };
3
+ /** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
4
+ export declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
8
5
  //# sourceMappingURL=scanEntityFiles.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scanEntityFiles.d.cts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;;iBAkBsB,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa"}
1
+ {"version":3,"file":"scanEntityFiles.d.cts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;wBAqBsB,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa"}
@@ -1,8 +1,5 @@
1
1
  import { Config } from "./config.mjs";
2
2
  import { DbMetadata } from "./EntityDbMetadata.mjs";
3
- //#region src/scanEntityFiles.d.ts
4
- /** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */
5
- declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
6
- //#endregion
7
- export { scanEntityFiles };
3
+ /** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
4
+ export declare function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void>;
8
5
  //# sourceMappingURL=scanEntityFiles.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scanEntityFiles.d.mts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;;iBAkBsB,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa"}
1
+ {"version":3,"file":"scanEntityFiles.d.mts","names":[],"sources":["../src/scanEntityFiles.ts"],"mappings":";;;wBAqBsB,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa"}
@@ -2,9 +2,10 @@ import "./config.js";
2
2
  import "./EntityDbMetadata.js";
3
3
  import { join } from "path";
4
4
  import { readFile } from "fs/promises";
5
- //#region src/scanEntityFiles.ts
5
+ // src/scanEntityFiles.ts
6
6
  const regex = /config\.setDefault\([\s\n]*["'](\w+)["']/g;
7
- /** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */
7
+ const transitionsRegex = /config\.(?:setTransitions|addTransitionRule|addTransitionReaction)\(\s*(?:(?:["'][^"']*["']|\w+)\s*,\s*(?=["']))?["'](\w+)["']/g;
8
+ /** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */
8
9
  async function scanEntityFiles(config, dbMeta) {
9
10
  await Promise.all(dbMeta.entities.map(async (entity) => {
10
11
  try {
@@ -14,6 +15,10 @@ async function scanEntityFiles(config, dbMeta) {
14
15
  const field = defaultableFields.find((f) => f.fieldName === match[1]);
15
16
  if (field) field.hasConfigDefault = true;
16
17
  }
18
+ for (const match of tsCode.matchAll(transitionsRegex)) {
19
+ const field = defaultableFields.find((f) => f.fieldName === match[1]);
20
+ if (field?.kind === "enum") field.hasTransitions = true;
21
+ }
17
22
  } catch (e) {}
18
23
  }));
19
24
  }
@@ -39,7 +44,6 @@ function recursiveDefaultableFields(dbMeta, entity) {
39
44
  ...entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []
40
45
  ];
41
46
  }
42
- //#endregion
43
47
  export { scanEntityFiles };
44
48
 
45
49
  //# sourceMappingURL=scanEntityFiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scanEntityFiles.js","names":[],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;AAeA,MAAM,QAAQ;;AAGd,eAAsB,gBAAgB,QAAgB,QAAmC;CACvF,MAAM,QAAQ,IACZ,OAAO,SAAS,IAAI,OAAO,WAAW;EACpC,IAAI;GAEF,MAAM,UAAU,MAAM,SAAS,KAAK,OAAO,mBAAmB,GAAG,OAAO,KAAK,IAAI,CAAC,EAAA,CAAG,SAAS;GAC9F,MAAM,oBAAoB,2BAA2B,QAAQ,MAAM;GACnE,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;IAC1C,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OACF,MAAM,mBAAmB;GAE7B;EACF,SAAS,GAAG,CAEZ;CACF,CAAC,CACH;AACF;;;;;;;;;;;;AAaA,SAAS,2BACP,QACA,QACqF;CACrF,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAI,OAAO,gBAAgB,2BAA2B,QAAQ,OAAO,eAAe,OAAO,cAAc,IAAI,CAAC;CAChH;AACF"}
1
+ {"version":3,"file":"scanEntityFiles.js","names":[],"sources":["../src/scanEntityFiles.ts"],"sourcesContent":["import { readFile } from \"fs/promises\";\nimport { join } from \"path\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type EnumField,\n type ManyToOneField,\n type PgEnumField,\n type PolymorphicField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\n\n// Erg, we need a regex in case the fieldName arg is wrapped onto a new line... :-/\nconst regex = /config\\.setDefault\\([\\s\\n]*[\"'](\\w+)[\"']/g;\n// Any transition method marks the field; addTransitionReaction may have a name before the field argument.\nconst transitionsRegex =\n /config\\.(?:setTransitions|addTransitionRule|addTransitionReaction)\\(\\s*(?:(?:[\"'][^\"']*[\"']|\\w+)\\s*,\\s*(?=[\"']))?[\"'](\\w+)[\"']/g;\n\n/** Scans the entity files themselves for usage hints (like `setDefault` or `setTransitions` calls) to drive our codegen output. */\nexport async function scanEntityFiles(config: Config, dbMeta: DbMetadata): Promise<void> {\n await Promise.all(\n dbMeta.entities.map(async (entity) => {\n try {\n // load the entity.ts file (as a promise with fs/promises)\n const tsCode = (await readFile(join(config.entitiesDirectory, `${entity.name}.ts`))).toString();\n const defaultableFields = recursiveDefaultableFields(dbMeta, entity);\n for (const match of tsCode.matchAll(regex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field) {\n field.hasConfigDefault = true;\n }\n }\n // Transition fields get `withStatus` factory opts and accessor names, i.e. `Draft`\n for (const match of tsCode.matchAll(transitionsRegex)) {\n const field = defaultableFields.find((f) => f.fieldName === match[1]);\n if (field?.kind === \"enum\") {\n field.hasTransitions = true;\n }\n }\n } catch (e) {\n // Ignore file not existing yet\n }\n }),\n );\n}\n\n/**\n * Traverse the entity inheritance tree to find all fields that can have defaults set on them.\n *\n * I.e. a column defined in a base CTI table like `publishers.foo_bar` having a `config.setDefault` in\n * `SmallPublisher` and/or `LargePublisher`, or the same scenario for an STI table like `tasks.foo_bar`\n * with `TaskNew` and/or `TaskOld`.\n *\n * NOTE: I suspect here could be some edge cases here that will need to be ironed out, but should work\n * for simple inheritance structures. In particular, there may be unexpected side effects if a base\n * class field has a default set in one subtype, but not another.\n */\nfunction recursiveDefaultableFields(\n dbMeta: DbMetadata,\n entity: EntityDbMetadata | undefined,\n): Array<PrimitiveField | EnumField | PgEnumField | ManyToOneField | PolymorphicField> {\n if (!entity) return [];\n return [\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.polymorphics,\n ...(entity.baseClassName ? recursiveDefaultableFields(dbMeta, dbMeta.entitiesByName[entity.baseClassName]) : []),\n ];\n}\n"],"mappings":";;;;;AAeA,MAAM,QAAQ;AAEd,MAAM,mBACJ;;AAGF,eAAsB,gBAAgB,QAAgB,QAAmC;CACvF,MAAM,QAAQ,IACZ,OAAO,SAAS,IAAI,OAAO,WAAW;EACpC,IAAI;GAEF,MAAM,UAAU,MAAM,SAAS,KAAK,OAAO,mBAAmB,GAAG,OAAO,KAAK,IAAI,CAAC,EAAA,CAAG,SAAS;GAC9F,MAAM,oBAAoB,2BAA2B,QAAQ,MAAM;GACnE,KAAK,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;IAC1C,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OACF,MAAM,mBAAmB;GAE7B;GAEA,KAAK,MAAM,SAAS,OAAO,SAAS,gBAAgB,GAAG;IACrD,MAAM,QAAQ,kBAAkB,MAAM,MAAM,EAAE,cAAc,MAAM,EAAE;IACpE,IAAI,OAAO,SAAS,QAClB,MAAM,iBAAiB;GAE3B;EACF,SAAS,GAAG,CAEZ;CACF,CAAC,CACH;AACF;;;;;;;;;;;;AAaA,SAAS,2BACP,QACA,QACqF;CACrF,IAAI,CAAC,QAAQ,OAAO,CAAC;CACrB,OAAO;EACL,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAG,OAAO;EACV,GAAI,OAAO,gBAAgB,2BAA2B,QAAQ,OAAO,eAAe,OAAO,cAAc,IAAI,CAAC;CAChH;AACF"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./EntityDbMetadata.cjs");
3
- //#region src/sortForeignKeys.ts
3
+ // src/sortForeignKeys.ts
4
4
  /**
5
5
  * Sorts entities by non-deferred foreign key order.
6
6
  *
@@ -93,7 +93,6 @@ function dfs(graph, visited, stack, path, current, target) {
93
93
  path.pop();
94
94
  return false;
95
95
  }
96
- //#endregion
97
96
  exports.sortByNonDeferredForeignKeys = sortByNonDeferredForeignKeys;
98
97
 
99
98
  //# sourceMappingURL=sortForeignKeys.cjs.map
@@ -1,5 +1,4 @@
1
1
  import { EntityDbMetadata } from "./EntityDbMetadata.cjs";
2
- //#region src/sortForeignKeys.d.ts
3
2
  /**
4
3
  * Sorts entities by non-deferred foreign key order.
5
4
  *
@@ -26,10 +25,8 @@ import { EntityDbMetadata } from "./EntityDbMetadata.cjs";
26
25
  * two arrays of all soft-cycle (nullable, fixup-able) and hard-cycle (not-nullable, blocking)
27
26
  * keys.
28
27
  */
29
- declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
28
+ export declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
30
29
  nullableCycles: string[];
31
30
  notNullCycles: string[];
32
31
  };
33
- //#endregion
34
- export { sortByNonDeferredForeignKeys };
35
32
  //# sourceMappingURL=sortForeignKeys.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sortForeignKeys.d.cts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BgB,6BAA6B,UAAU;EACrD;EACA"}
1
+ {"version":3,"file":"sortForeignKeys.d.cts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,6BAA6B,UAAU;EACrD;EACA"}
@@ -1,5 +1,4 @@
1
1
  import { EntityDbMetadata } from "./EntityDbMetadata.mjs";
2
- //#region src/sortForeignKeys.d.ts
3
2
  /**
4
3
  * Sorts entities by non-deferred foreign key order.
5
4
  *
@@ -26,10 +25,8 @@ import { EntityDbMetadata } from "./EntityDbMetadata.mjs";
26
25
  * two arrays of all soft-cycle (nullable, fixup-able) and hard-cycle (not-nullable, blocking)
27
26
  * keys.
28
27
  */
29
- declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
28
+ export declare function sortByNonDeferredForeignKeys(entities: EntityDbMetadata[]): {
30
29
  nullableCycles: string[];
31
30
  notNullCycles: string[];
32
31
  };
33
- //#endregion
34
- export { sortByNonDeferredForeignKeys };
35
32
  //# sourceMappingURL=sortForeignKeys.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sortForeignKeys.d.mts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BgB,6BAA6B,UAAU;EACrD;EACA"}
1
+ {"version":3,"file":"sortForeignKeys.d.mts","names":[],"sources":["../src/sortForeignKeys.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,6BAA6B,UAAU;EACrD;EACA"}
@@ -1,5 +1,5 @@
1
1
  import "./EntityDbMetadata.js";
2
- //#region src/sortForeignKeys.ts
2
+ // src/sortForeignKeys.ts
3
3
  /**
4
4
  * Sorts entities by non-deferred foreign key order.
5
5
  *
@@ -92,7 +92,6 @@ function dfs(graph, visited, stack, path, current, target) {
92
92
  path.pop();
93
93
  return false;
94
94
  }
95
- //#endregion
96
95
  export { sortByNonDeferredForeignKeys };
97
96
 
98
97
  //# sourceMappingURL=sortForeignKeys.js.map