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,10 +1,9 @@
1
1
  import { Config } from "./config.cjs";
2
- import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.cjs";
3
2
  import { EnumMetadata, EnumRow, PgEnumMetadata } from "./loadMetadata.cjs";
3
+ import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.cjs";
4
4
  import { Code, Import } from "ts-poet";
5
- //#region src/EntityDbMetadata.d.ts
6
5
  /** All the entities + enums in our database. */
7
- interface DbMetadata {
6
+ export interface DbMetadata {
8
7
  entities: EntityDbMetadata[];
9
8
  /** Type name i.e. `Author` to metadata. */
10
9
  entitiesByName: Record<string, EntityDbMetadata>;
@@ -16,7 +15,7 @@ interface DbMetadata {
16
15
  totalTables: number;
17
16
  }
18
17
  /** Codegen-time metadata about a given domain entity. */
19
- type Entity = {
18
+ export type Entity = {
20
19
  name: string;
21
20
  /** The _type_ symbol pointing to the entity itself. */
22
21
  type: Import;
@@ -56,7 +55,7 @@ type Entity = {
56
55
  /** i.e. `AuthorScopes`. */
57
56
  scopesName: string;
58
57
  };
59
- type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange";
58
+ export type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange" | "vector";
60
59
  /**
61
60
  * A logical entity field.
62
61
  *
@@ -66,8 +65,8 @@ interface Field {
66
65
  fieldName: string;
67
66
  ignore?: boolean;
68
67
  }
69
- type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "bigint" | "Uint8Array" | Code;
70
- type PrimitiveField = Field & {
68
+ export type PrimitiveTypescriptType = "boolean" | "string" | "number" | "number[]" | "Object" | "bigint" | "Uint8Array" | Code;
69
+ export type PrimitiveField = Field & {
71
70
  kind: "primitive";
72
71
  columnName: string;
73
72
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -90,7 +89,7 @@ type PrimitiveField = Field & {
90
89
  hasConfigDefault: boolean;
91
90
  lazy?: boolean;
92
91
  };
93
- type EnumField = Field & {
92
+ export type EnumField = Field & {
94
93
  kind: "enum";
95
94
  columnName: string;
96
95
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -108,8 +107,10 @@ type EnumField = Field & {
108
107
  notNull: boolean;
109
108
  isArray: boolean;
110
109
  hasConfigDefault: boolean;
110
+ /** Whether the entity file calls `config.setTransitions`, `addTransitionRule`, or `addTransitionReaction` on this field, set by `scanEntityFiles`. */
111
+ hasTransitions: boolean;
111
112
  };
112
- type PgEnumField = Field & {
113
+ export type PgEnumField = Field & {
113
114
  kind: "pg-enum";
114
115
  columnName: string;
115
116
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -127,7 +128,7 @@ type PgEnumField = Field & {
127
128
  hasConfigDefault: boolean;
128
129
  };
129
130
  /** I.e. a `Book.author` reference pointing to an `Author`. */
130
- type ManyToOneField = Field & {
131
+ export type ManyToOneField = Field & {
131
132
  kind: "m2o";
132
133
  columnName: string;
133
134
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -146,7 +147,7 @@ type ManyToOneField = Field & {
146
147
  onDelete: Action;
147
148
  };
148
149
  /** I.e. a `Author.books` collection. */
149
- type OneToManyField = Field & {
150
+ export type OneToManyField = Field & {
150
151
  kind: "o2m";
151
152
  singularName: string;
152
153
  otherEntity: Entity;
@@ -161,14 +162,14 @@ type OneToManyField = Field & {
161
162
  softDeletes: "include" | "exclude" | undefined;
162
163
  };
163
164
  /** I.e. a `Author.image` reference when `image.author_id` is unique. */
164
- type OneToOneField = Field & {
165
+ export type OneToOneField = Field & {
165
166
  kind: "o2o";
166
167
  otherEntity: Entity;
167
168
  otherFieldName: string;
168
169
  otherColumnName: string;
169
170
  otherColumnNotNull: boolean;
170
171
  };
171
- type ManyToManyField = Field & {
172
+ export type ManyToManyField = Field & {
172
173
  kind: "m2m";
173
174
  joinTableName: string;
174
175
  singularName: string;
@@ -184,7 +185,7 @@ type ManyToManyField = Field & {
184
185
  hasJoinTableId: boolean;
185
186
  };
186
187
  /** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */
187
- type ManyToManyEnumField = Field & {
188
+ export type ManyToManyEnumField = Field & {
188
189
  kind: "m2mEnum";
189
190
  joinTableName: string;
190
191
  /** The entity's FK column, e.g. `publisher_id`. */
@@ -200,7 +201,7 @@ type ManyToManyEnumField = Field & {
200
201
  hasJoinTableId: boolean;
201
202
  };
202
203
  /** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */
203
- type PolymorphicField = Field & {
204
+ export type PolymorphicField = Field & {
204
205
  kind: "poly";
205
206
  fieldType: string;
206
207
  notNull: boolean;
@@ -208,7 +209,7 @@ type PolymorphicField = Field & {
208
209
  components: PolymorphicFieldComponent[];
209
210
  };
210
211
  /** A column such as `parent_book_id` or `parent_book_review_id`. */
211
- type PolymorphicFieldComponent = {
212
+ export type PolymorphicFieldComponent = {
212
213
  columnName: string;
213
214
  /** Physical table owner, unchanged by domain inheritance specialization. */
214
215
  columnOwner: Entity;
@@ -218,12 +219,12 @@ type PolymorphicFieldComponent = {
218
219
  constraintName: string;
219
220
  notNull: false;
220
221
  };
221
- type FieldNameOverrides = {
222
+ export type FieldNameOverrides = {
222
223
  fieldName?: string;
223
224
  otherFieldName?: string;
224
225
  };
225
226
  /** Adapts PostgreSQL catalog metadata into our specific ORM types. */
226
- declare class EntityDbMetadata {
227
+ export declare class EntityDbMetadata {
227
228
  entity: Entity;
228
229
  primaryKey: PrimitiveField;
229
230
  primitives: PrimitiveField[];
@@ -265,16 +266,16 @@ declare class EntityDbMetadata {
265
266
  get nonDeferredManyToManyFks(): Array<ManyToManyField>;
266
267
  }
267
268
  /** Finds the field name for o2o side of a o2o/m2o. */
268
- declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
269
- declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
270
- declare function manyToManyName(column: Column): string;
269
+ export declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
270
+ export declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
271
+ export declare function manyToManyName(column: Column): string;
271
272
  /** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
272
- declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
273
+ export declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
273
274
  fieldName: string;
274
275
  singularName: string;
275
276
  };
276
- declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
277
- declare function makeEntity(entityName: string): Entity;
277
+ export declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
278
+ export declare function makeEntity(entityName: string): Entity;
278
279
  /**
279
280
  * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
280
281
  *
@@ -284,18 +285,25 @@ declare function makeEntity(entityName: string): Entity;
284
285
  *
285
286
  * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
286
287
  */
287
- declare function canonicalizeOtherEntities(db: DbMetadata): void;
288
+ export declare function canonicalizeOtherEntities(db: DbMetadata): void;
288
289
  /**
289
290
  * Rewrites codegen'd type names that collide with another exported type name.
290
291
  *
291
292
  * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
292
293
  * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
293
294
  * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
295
+ * Polymorphic unions yield to these API names by appending `Poly` until the name is available.
294
296
  *
295
297
  * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
296
298
  * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
297
299
  */
298
- declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
299
- //#endregion
300
- export { DatabaseColumnType, DbMetadata, Entity, EntityDbMetadata, EnumField, FieldNameOverrides, ManyToManyEnumField, ManyToManyField, ManyToOneField, OneToManyField, OneToOneField, PgEnumField, PolymorphicField, PolymorphicFieldComponent, PrimitiveField, PrimitiveTypescriptType, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
300
+ export declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
301
+ /**
302
+ * Assigns family-wide scalar-field ordinals for metadata and generated first-read guards.
303
+ *
304
+ * Inherited getters must use the same bits on every subtype, including fields that
305
+ * specialize an inherited field. Value storage remains the existing data bag.
306
+ */
307
+ export declare function getFieldReadIndexes(meta: EntityDbMetadata): ReadonlyMap<string, number>;
308
+ export {};
301
309
  //# sourceMappingURL=EntityDbMetadata.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityDbMetadata.d.cts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":";;;;;;UAmDiB;EACf,UAAU;;EAEV,gBAAgB,eAAe;EAC/B,OAAO;E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Z;EACA;;EAEA;EAEA,WAAW,0BAA0B;EACrC,cAAc;EACd;EACA;EACA;EACA;EACA,aAAa;EACb,WAAW;EACX,aAAa;EACb;EACA;EACA;;YAGU,YAAY;EACtB;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;EAEA;;YAGU,cAAc;EACxB;EACA;;EAEA,aAAa;EACb;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;YAIU,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,UAAU;;;YAIA,iBAAiB;EAC3B;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;IAAW;IAAe;;EAC1B;;;YAIU,gBAAgB;EAC1B;EACA,aAAa;EACb;EACA;EACA;;YAGU,kBAAkB;EAC5B;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;;EAEA;;;YAIU,sBAAsB;EAChC;EACA;;EAEA;;EAEA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;;EAEV;;;YAIU,mBAAmB;EAC7B;EACA;EACA;EACA;EACA,YAAY;;;YAIF;EACV;;EAEA,aAAa;EACb;EACA,aAAa;EACb;EACA;EACA;;YAGU;EACV;EACA;;;qBAIW;EACX,QAAQ;EACR,YAAY;EACZ,YAAY;EACZ,OAAO;EACP,SAAS;EACT,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,WAAW;EACX,aAAa;EACb,kBAAkB;EAClB,iBAAiB;EACjB,cAAc;EACd;EACA;EACA,WAAW;EACX,WAAW;EACX,WAAW;EACX;EACA,UAAU;EACV,UAAU;EACV;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;EAEA,mBAAmB;;EAEnB,gBAAgB;EAEhB,YAAY,QAAQ,QAAQ,OAAO,OAAO,QAAO;MAqI7C;MAIA,kBAAkB,MAAM,iBAAiB;MAOzC,4BAA4B,MAAM;;;wBAucxB,aACd,QAAQ,QAER,WAAW,QAEX,WAAW,QACX,GAAG,cAAc;wBAgCH,cAAc,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,cAAc;wBAmB/D,eAAe,QAAQ;;wBAUvB,eACd,QAAQ,QAER,cAAc,QAEd,kBAAkB,QAClB,GAAG,cAAc,cAAc;EAC5B;EAAmB;;wBA4BR,4BAA4B,QAAQ;wBAwBpC,WAAW,qBAAqB;;;;;;;;;;wBA6BhC,0BAA0B,IAAI;;;;;;;;;;;;wBAiC9B,qBAAqB,QAAQ,QAAQ,IAAI;;;;;;;wBA4IzC,oBAAoB,MAAM,mBAAmB"}
@@ -1,10 +1,9 @@
1
1
  import { Config } from "./config.mjs";
2
- import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.mjs";
3
2
  import { EnumMetadata, EnumRow, PgEnumMetadata } from "./loadMetadata.mjs";
3
+ import { Action, Column, M2MRelation, M2ORelation, O2MRelation, Table } from "./pgMetadata.mjs";
4
4
  import { Code, Import } from "ts-poet";
5
- //#region src/EntityDbMetadata.d.ts
6
5
  /** All the entities + enums in our database. */
7
- interface DbMetadata {
6
+ export interface DbMetadata {
8
7
  entities: EntityDbMetadata[];
9
8
  /** Type name i.e. `Author` to metadata. */
10
9
  entitiesByName: Record<string, EntityDbMetadata>;
@@ -16,7 +15,7 @@ interface DbMetadata {
16
15
  totalTables: number;
17
16
  }
18
17
  /** Codegen-time metadata about a given domain entity. */
19
- type Entity = {
18
+ export type Entity = {
20
19
  name: string;
21
20
  /** The _type_ symbol pointing to the entity itself. */
22
21
  type: Import;
@@ -56,7 +55,7 @@ type Entity = {
56
55
  /** i.e. `AuthorScopes`. */
57
56
  scopesName: string;
58
57
  };
59
- type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange";
58
+ export type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange" | "vector";
60
59
  /**
61
60
  * A logical entity field.
62
61
  *
@@ -66,8 +65,8 @@ interface Field {
66
65
  fieldName: string;
67
66
  ignore?: boolean;
68
67
  }
69
- type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "bigint" | "Uint8Array" | Code;
70
- type PrimitiveField = Field & {
68
+ export type PrimitiveTypescriptType = "boolean" | "string" | "number" | "number[]" | "Object" | "bigint" | "Uint8Array" | Code;
69
+ export type PrimitiveField = Field & {
71
70
  kind: "primitive";
72
71
  columnName: string;
73
72
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -90,7 +89,7 @@ type PrimitiveField = Field & {
90
89
  hasConfigDefault: boolean;
91
90
  lazy?: boolean;
92
91
  };
93
- type EnumField = Field & {
92
+ export type EnumField = Field & {
94
93
  kind: "enum";
95
94
  columnName: string;
96
95
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -108,8 +107,10 @@ type EnumField = Field & {
108
107
  notNull: boolean;
109
108
  isArray: boolean;
110
109
  hasConfigDefault: boolean;
110
+ /** Whether the entity file calls `config.setTransitions`, `addTransitionRule`, or `addTransitionReaction` on this field, set by `scanEntityFiles`. */
111
+ hasTransitions: boolean;
111
112
  };
112
- type PgEnumField = Field & {
113
+ export type PgEnumField = Field & {
113
114
  kind: "pg-enum";
114
115
  columnName: string;
115
116
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -127,7 +128,7 @@ type PgEnumField = Field & {
127
128
  hasConfigDefault: boolean;
128
129
  };
129
130
  /** I.e. a `Book.author` reference pointing to an `Author`. */
130
- type ManyToOneField = Field & {
131
+ export type ManyToOneField = Field & {
131
132
  kind: "m2o";
132
133
  columnName: string;
133
134
  /** Physical table owner, unchanged by domain inheritance specialization. */
@@ -146,7 +147,7 @@ type ManyToOneField = Field & {
146
147
  onDelete: Action;
147
148
  };
148
149
  /** I.e. a `Author.books` collection. */
149
- type OneToManyField = Field & {
150
+ export type OneToManyField = Field & {
150
151
  kind: "o2m";
151
152
  singularName: string;
152
153
  otherEntity: Entity;
@@ -161,14 +162,14 @@ type OneToManyField = Field & {
161
162
  softDeletes: "include" | "exclude" | undefined;
162
163
  };
163
164
  /** I.e. a `Author.image` reference when `image.author_id` is unique. */
164
- type OneToOneField = Field & {
165
+ export type OneToOneField = Field & {
165
166
  kind: "o2o";
166
167
  otherEntity: Entity;
167
168
  otherFieldName: string;
168
169
  otherColumnName: string;
169
170
  otherColumnNotNull: boolean;
170
171
  };
171
- type ManyToManyField = Field & {
172
+ export type ManyToManyField = Field & {
172
173
  kind: "m2m";
173
174
  joinTableName: string;
174
175
  singularName: string;
@@ -184,7 +185,7 @@ type ManyToManyField = Field & {
184
185
  hasJoinTableId: boolean;
185
186
  };
186
187
  /** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */
187
- type ManyToManyEnumField = Field & {
188
+ export type ManyToManyEnumField = Field & {
188
189
  kind: "m2mEnum";
189
190
  joinTableName: string;
190
191
  /** The entity's FK column, e.g. `publisher_id`. */
@@ -200,7 +201,7 @@ type ManyToManyEnumField = Field & {
200
201
  hasJoinTableId: boolean;
201
202
  };
202
203
  /** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */
203
- type PolymorphicField = Field & {
204
+ export type PolymorphicField = Field & {
204
205
  kind: "poly";
205
206
  fieldType: string;
206
207
  notNull: boolean;
@@ -208,7 +209,7 @@ type PolymorphicField = Field & {
208
209
  components: PolymorphicFieldComponent[];
209
210
  };
210
211
  /** A column such as `parent_book_id` or `parent_book_review_id`. */
211
- type PolymorphicFieldComponent = {
212
+ export type PolymorphicFieldComponent = {
212
213
  columnName: string;
213
214
  /** Physical table owner, unchanged by domain inheritance specialization. */
214
215
  columnOwner: Entity;
@@ -218,12 +219,12 @@ type PolymorphicFieldComponent = {
218
219
  constraintName: string;
219
220
  notNull: false;
220
221
  };
221
- type FieldNameOverrides = {
222
+ export type FieldNameOverrides = {
222
223
  fieldName?: string;
223
224
  otherFieldName?: string;
224
225
  };
225
226
  /** Adapts PostgreSQL catalog metadata into our specific ORM types. */
226
- declare class EntityDbMetadata {
227
+ export declare class EntityDbMetadata {
227
228
  entity: Entity;
228
229
  primaryKey: PrimitiveField;
229
230
  primitives: PrimitiveField[];
@@ -265,16 +266,16 @@ declare class EntityDbMetadata {
265
266
  get nonDeferredManyToManyFks(): Array<ManyToManyField>;
266
267
  }
267
268
  /** Finds the field name for o2o side of a o2o/m2o. */
268
- declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
269
- declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
270
- declare function manyToManyName(column: Column): string;
269
+ export declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
270
+ export declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
271
+ export declare function manyToManyName(column: Column): string;
271
272
  /** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
272
- declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
273
+ export declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
273
274
  fieldName: string;
274
275
  singularName: string;
275
276
  };
276
- declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
277
- declare function makeEntity(entityName: string): Entity;
277
+ export declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
278
+ export declare function makeEntity(entityName: string): Entity;
278
279
  /**
279
280
  * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
280
281
  *
@@ -284,18 +285,25 @@ declare function makeEntity(entityName: string): Entity;
284
285
  *
285
286
  * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
286
287
  */
287
- declare function canonicalizeOtherEntities(db: DbMetadata): void;
288
+ export declare function canonicalizeOtherEntities(db: DbMetadata): void;
288
289
  /**
289
290
  * Rewrites codegen'd type names that collide with another exported type name.
290
291
  *
291
292
  * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
292
293
  * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
293
294
  * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
295
+ * Polymorphic unions yield to these API names by appending `Poly` until the name is available.
294
296
  *
295
297
  * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
296
298
  * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
297
299
  */
298
- declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
299
- //#endregion
300
- export { DatabaseColumnType, DbMetadata, Entity, EntityDbMetadata, EnumField, FieldNameOverrides, ManyToManyEnumField, ManyToManyField, ManyToOneField, OneToManyField, OneToOneField, PgEnumField, PolymorphicField, PolymorphicFieldComponent, PrimitiveField, PrimitiveTypescriptType, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
300
+ export declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
301
+ /**
302
+ * Assigns family-wide scalar-field ordinals for metadata and generated first-read guards.
303
+ *
304
+ * Inherited getters must use the same bits on every subtype, including fields that
305
+ * specialize an inherited field. Value storage remains the existing data bag.
306
+ */
307
+ export declare function getFieldReadIndexes(meta: EntityDbMetadata): ReadonlyMap<string, number>;
308
+ export {};
301
309
  //# sourceMappingURL=EntityDbMetadata.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityDbMetadata.d.mts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":";;;;;;UAmDiB;EACf,UAAU;;EAEV,gBAAgB,eAAe;EAC/B,OAAO;EACP,SAAS;EACT;;EAEA;EACA;;;KAIU;EACV;;EAEA,MAAM;;EAEN,YAAY;;EAEZ,qBAAqB;;EAErB;;EAEA,UAAU;;EAEV,QAAQ;;EAER,WAAW;;EAEX,aAAa;EACb,UAAU;;EAKV;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;KAGU;;;;;;UAgCF;EACR;EACA;;KAGU,iGAAiG;KAEjG,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;;EAEA;EAEA,WAAW,0BAA0B;EACrC,cAAc;EACd;EACA;EACA;EACA;EACA,aAAa;EACb,WAAW;EACX,aAAa;EACb;EACA;EACA;;KAGU,YAAY;EACtB;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;KAGU,cAAc;EACxB;EACA;;EAEA,aAAa;EACb;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;KAIU,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,UAAU;;;KAIA,iBAAiB;EAC3B;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;IAAW;IAAe;;EAC1B;;;KAIU,gBAAgB;EAC1B;EACA,aAAa;EACb;EACA;EACA;;KAGU,kBAAkB;EAC5B;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA;;EAEA;;;KAIU,sBAAsB;EAChC;EACA;;EAEA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a;EACb,kBAAkB;EAClB,iBAAiB;EACjB,cAAc;EACd;EACA;EACA,WAAW;EACX,WAAW;EACX,WAAW;EACX;EACA,UAAU;EACV,UAAU;EACV;;EAEA;;EAEA;EACA;EACA;EACA;;EAEA;;EAEA,mBAAmB;;EAEnB,gBAAgB;EAEhB,YAAY,QAAQ,QAAQ,OAAO,OAAO,QAAO;MAqI7C;MAIA,kBAAkB,MAAM,iBAAiB;MAOzC,4BAA4B,MAAM;;;wBAucxB,aACd,QAAQ,QAER,WAAW,QAEX,WAAW,QACX,GAAG,cAAc;wBAgCH,cAAc,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,cAAc;wBAmB/D,eAAe,QAAQ;;wBAUvB,eACd,QAAQ,QAER,cAAc,QAEd,kBAAkB,QAClB,GAAG,cAAc,cAAc;EAC5B;EAAmB;;wBA4BR,4BAA4B,QAAQ;wBAwBpC,WAAW,qBAAqB;;;;;;;;;;wBA6BhC,0BAA0B,IAAI;;;;;;;;;;;;wBAiC9B,qBAAqB,QAAQ,QAAQ,IAAI;;;;;;;wBA4IzC,oBAAoB,MAAM,mBAAmB"}
@@ -1,13 +1,13 @@
1
- import { EnumType, M2ORelation } from "./pgMetadata.js";
2
- import { fail, isEnumTable, isJoinTable, isSubClassTable, joinTableHasId, mapSimpleDbTypeToTypescriptType, parseOrder, tableToEntityName } from "./utils.js";
3
1
  import { fieldTypeConfig, getTimestampConfig, isFieldHasDefault, isFieldIgnored, isGetterField, isLargeCollection, isLazyField, isProtected, isReactiveField, isReactiveManyToMany, isReactiveReference, ormMaintainedFields, serdeConfig, softDeletesConfig, superstructConfig, zodSchemaConfig } from "./config.js";
4
- import { Zod } from "./symbols.js";
5
2
  import "./loadMetadata.js";
3
+ import { EnumType, M2ORelation } from "./pgMetadata.js";
4
+ import { Zod } from "./symbols.js";
5
+ import { fail, isEnumTable, isJoinTable, isSubClassTable, joinTableHasId, mapSimpleDbTypeToTypescriptType, parseOrder, tableToEntityName } from "./utils.js";
6
6
  import { camelCase, pascalCase, snakeCase } from "change-case";
7
7
  import { groupBy } from "joist-utils";
8
8
  import pluralize from "pluralize";
9
9
  import { Import, code, imp } from "ts-poet";
10
- //#region src/EntityDbMetadata.ts
10
+ // src/EntityDbMetadata.ts
11
11
  const { plural, singular } = pluralize;
12
12
  /** Adapts PostgreSQL catalog metadata into our specific ORM types. */
13
13
  var EntityDbMetadata = class {
@@ -120,7 +120,7 @@ function inferUniqueConstraints(meta, table) {
120
120
  /** Returns the queryable field name for a unique constraint column. */
121
121
  function fieldNameForColumn(meta, columnName) {
122
122
  const primitive = meta.primitives.find((field) => field.columnName === columnName);
123
- if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde) return primitive.fieldName;
123
+ if (primitive && !primitive.derived && !primitive.customSerde) return primitive.fieldName;
124
124
  const enumField = meta.enums.find((field) => field.columnName === columnName);
125
125
  if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;
126
126
  const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
@@ -251,7 +251,8 @@ function newEnumField(config, entity, r, enums) {
251
251
  ignore,
252
252
  enumRows: enums[r.targetTable.name].rows,
253
253
  isArray: false,
254
- hasConfigDefault
254
+ hasConfigDefault,
255
+ hasTransitions: false
255
256
  };
256
257
  }
257
258
  function newEnumArrayField(config, entity, column, enums) {
@@ -284,7 +285,8 @@ function newEnumArrayField(config, entity, column, enums) {
284
285
  ignore,
285
286
  enumRows: enums[enumTable].rows,
286
287
  isArray: true,
287
- hasConfigDefault
288
+ hasConfigDefault,
289
+ hasTransitions: false
288
290
  };
289
291
  }
290
292
  function newPgEnumField(config, entity, column) {
@@ -570,6 +572,7 @@ function canonicalizeOtherEntities(db) {
570
572
  * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
571
573
  * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
572
574
  * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
575
+ * Polymorphic unions yield to these API names by appending `Poly` until the name is available.
573
576
  *
574
577
  * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
575
578
  * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
@@ -582,6 +585,21 @@ function resolveNameConflicts(config, db) {
582
585
  }
583
586
  for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);
584
587
  for (const meta of db.entities) if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);
588
+ for (const meta of db.entities) {
589
+ const keys = Object.keys(entitySymbolNames(meta.name));
590
+ for (const key of keys) reserved.add(meta.entity[key]);
591
+ reserved.add(`${meta.name}Codegen`).add(`${meta.name}Columns`);
592
+ }
593
+ const polymorphics = db.entities.flatMap((meta) => meta.polymorphics);
594
+ const unionNames = new Set(polymorphics.map((poly) => poly.fieldType));
595
+ for (const poly of polymorphics) {
596
+ if (reserved.has(poly.fieldType)) {
597
+ let name = `${poly.fieldType}Poly`;
598
+ while (reserved.has(name) || unionNames.has(name)) name += "Poly";
599
+ poly.fieldType = name;
600
+ }
601
+ reserved.add(poly.fieldType);
602
+ }
585
603
  }
586
604
  /** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */
587
605
  function entitySymbolNames(name, reserved) {
@@ -655,7 +673,30 @@ function userFieldTypeType(s) {
655
673
  function serdeType(s) {
656
674
  return Import.from(s);
657
675
  }
658
- //#endregion
659
- export { EntityDbMetadata, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
676
+ /**
677
+ * Assigns family-wide scalar-field ordinals for metadata and generated first-read guards.
678
+ *
679
+ * Inherited getters must use the same bits on every subtype, including fields that
680
+ * specialize an inherited field. Value storage remains the existing data bag.
681
+ */
682
+ function getFieldReadIndexes(meta) {
683
+ let root = meta;
684
+ while (root.baseType) root = root.baseType;
685
+ const pending = [root];
686
+ const names = /* @__PURE__ */ new Set(["id"]);
687
+ while (pending.length > 0) {
688
+ const current = pending.pop();
689
+ for (const field of [
690
+ ...current.primitives,
691
+ ...current.enums,
692
+ ...current.pgEnums,
693
+ ...current.manyToOnes,
694
+ ...current.polymorphics
695
+ ]) names.add(field.fieldName);
696
+ pending.push(...current.subTypes);
697
+ }
698
+ return new Map([...names].sort().map((name, index) => [name, index]));
699
+ }
700
+ export { EntityDbMetadata, canonicalizeOtherEntities, collectionName, failIfOverlappingFieldNames, getFieldReadIndexes, makeEntity, manyToManyName, oneToOneName, referenceName, resolveNameConflicts };
660
701
 
661
702
  //# sourceMappingURL=EntityDbMetadata.js.map