joist-codegen 2.3.0-next.66 → 2.3.0-next.68

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.
@@ -162,6 +162,7 @@ function newPrimitive(config, entity, column, table) {
162
162
  const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
163
163
  return {
164
164
  kind: "primitive",
165
+ columnOwner: entity,
165
166
  columnNotNull: column.notNull,
166
167
  fieldName,
167
168
  columnName,
@@ -207,6 +208,7 @@ function newEnumField(config, entity, r, enums) {
207
208
  const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
208
209
  return {
209
210
  kind: "enum",
211
+ columnOwner: entity,
210
212
  columnNotNull: column.notNull,
211
213
  fieldName,
212
214
  columnName,
@@ -239,6 +241,7 @@ function newEnumArrayField(config, entity, column, enums) {
239
241
  const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
240
242
  return {
241
243
  kind: "enum",
244
+ columnOwner: entity,
242
245
  columnNotNull: column.notNull,
243
246
  fieldName,
244
247
  columnName,
@@ -265,6 +268,7 @@ function newPgEnumField(config, entity, column) {
265
268
  const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
266
269
  return {
267
270
  kind: "pg-enum",
271
+ columnOwner: entity,
268
272
  columnNotNull: column.notNull,
269
273
  fieldName,
270
274
  columnName,
@@ -293,6 +297,7 @@ function newManyToOneField(config, entity, r) {
293
297
  const hasConfigDefault = require_config.isFieldHasDefault(config, entity, fieldName);
294
298
  return {
295
299
  kind: "m2o",
300
+ columnOwner: entity,
296
301
  columnNotNull: column.notNull,
297
302
  fieldName,
298
303
  columnName,
@@ -408,6 +413,7 @@ function newPolymorphicFieldComponent(config, entity, r) {
408
413
  const otherEntity = makeEntity(require_utils.tableToEntityName(config, r.targetTable));
409
414
  return {
410
415
  columnName,
416
+ columnOwner: entity,
411
417
  otherEntity,
412
418
  otherFieldName: column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName,
413
419
  isDeferredAndDeferrable: r.foreignKey.isDeferred && r.foreignKey.isDeferrable,
@@ -1 +1 @@
1
- {"version":3,"file":"EntityDbMetadata.cjs","names":["tableToEntityName","isSubClassTable","fail","isEnumTable","isJoinTable","isReactiveReference","getTimestampConfig","snakeCase","serdeConfig","superstructConfig","zodSchemaConfig","fieldTypeConfig","isFieldHasDefault","isProtected","isFieldIgnored","Import","isLazyField","ormMaintainedFields","isGetterField","isReactiveField","imp","pascalCase","isLargeCollection","parseOrder","softDeletesConfig","isReactiveManyToMany","joinTableHasId","M2ORelation","camelCase","groupBy","mapSimpleDbTypeToTypescriptType","EnumType","Zod"],"sources":["../src/EntityDbMetadata.ts"],"sourcesContent":["import { camelCase, pascalCase, snakeCase } from \"change-case\";\nimport { groupBy } from \"joist-utils\";\nimport {\n type Action,\n type Column,\n EnumType,\n type Index,\n type JSONData,\n type M2MRelation,\n M2ORelation,\n type O2MRelation,\n type Table,\n} from \"pg-structure\";\nimport pluralize from \"pluralize\";\nimport { type Code, Import, code, imp } from \"ts-poet\";\n\nimport {\n type Config,\n fieldTypeConfig,\n getTimestampConfig,\n isFieldHasDefault,\n isFieldIgnored,\n isGetterField,\n isLargeCollection,\n isLazyField,\n isProtected,\n isReactiveField,\n isReactiveManyToMany,\n isReactiveReference,\n ormMaintainedFields,\n serdeConfig,\n softDeletesConfig,\n superstructConfig,\n zodSchemaConfig,\n} from \"./config.ts\";\nimport { type EnumMetadata, type EnumRow, type PgEnumMetadata } from \"./loadMetadata.ts\";\nimport { Zod } from \"./symbols.ts\";\nimport {\n fail,\n isEnumTable,\n isJoinTable,\n isSubClassTable,\n joinTableHasId,\n mapSimpleDbTypeToTypescriptType,\n parseOrder,\n tableToEntityName,\n} from \"./utils.ts\";\n\nconst { plural, singular } = pluralize;\n\n/** All the entities + enums in our database. */\nexport interface DbMetadata {\n entities: EntityDbMetadata[];\n /** Type name i.e. `Author` to metadata. */\n entitiesByName: Record<string, EntityDbMetadata>;\n enums: EnumMetadata;\n pgEnums: PgEnumMetadata;\n joinTables: string[];\n /** Other non-joist tables in the schema. */\n otherTables: string[];\n totalTables: number;\n}\n\n/** Codegen-time metadata about a given domain entity. */\nexport type Entity = {\n name: string;\n /** The _type_ symbol pointing to the entity itself. */\n type: Import;\n /** The symbol pointing to the entity itself. */\n typeSymbol: Import;\n /** The symbol pointing to the entity itself, directly rather than via entities.ts */\n typeForMetadataFile: Import;\n /** The name of the entity's runtime metadata const. */\n metaName: string;\n /** The symbol pointing to the entity's runtime metadata const. */\n metaType: Import;\n /** The symbol pointing to the entity's EntityId type. */\n idType: Import;\n /** The symbol pointing to the entity's Order type. */\n orderType: Import;\n /** The symbol pointing to the entity's config const. */\n configConst: Import;\n optsType: Import;\n // The names of the entity's codegen'd types, i.e. `AuthorId`, that `resolveNameConflicts` rewrites\n // to `Author_Id` when they would collide with another entity/enum name. The `Import`s above\n // (`idType`/`orderType`/`optsType`) are rebuilt to match when that happens.\n /** i.e. `AuthorId` (or `Author_Id` on conflict). */\n idName: string;\n /** i.e. `AuthorFields`. */\n fieldsName: string;\n /** i.e. `AuthorOpts`. */\n optsName: string;\n /** i.e. `AuthorIdsOpts`. */\n idsOptsName: string;\n /** i.e. `AuthorFilter`. */\n filterName: string;\n /** i.e. `AuthorGraphQLFilter`. */\n graphqlFilterName: string;\n /** i.e. `AuthorOrder`. */\n orderName: string;\n /** i.e. `AuthorFactoryExtras`. */\n factoryExtrasName: string;\n /** i.e. `AuthorScope`. */\n scopeName: string;\n /** i.e. `AuthorScopes`. */\n scopesName: string;\n};\n\nexport type DatabaseColumnType =\n | \"boolean\"\n | \"int\"\n | \"uuid\"\n | \"numeric\"\n | \"smallint\"\n | \"integer\"\n | \"bigint\"\n | \"decimal\"\n | \"real\"\n | \"smallserial\"\n | \"serial\"\n | \"bigserial\"\n | \"double precision\"\n | \"text\"\n | \"citext\"\n | \"character varying\"\n | \"varchar\"\n | \"time without time zone\"\n | \"timestamp with time zone\"\n | \"timestamp without time zone\"\n | \"date\"\n | \"jsonb\"\n | \"bytea\"\n | \"tsvector\"\n | \"tstzrange\";\n\n/**\n * A logical entity field.\n *\n * I.e. it may be a physical db column, or multiple physical db columns, or a \"virtual\" field like\n * the one-to-many collection side of a many-to-one foreign key. */\ninterface Field {\n fieldName: string;\n ignore?: boolean;\n}\n\nexport type PrimitiveTypescriptType = \"boolean\" | \"string\" | \"number\" | \"Object\" | \"bigint\" | \"Uint8Array\" | Code;\n\nexport type PrimitiveField = Field & {\n kind: \"primitive\";\n columnName: string;\n columnType: DatabaseColumnType;\n columnDefault: number | boolean | string | null;\n columnGenerated: boolean;\n /** Database nullability, unchanged by domain inheritance specialization. */\n columnNotNull: boolean;\n // The fieldType might be code for jsonb columns or primitive array columns, i.e. string[]\n fieldType: PrimitiveTypescriptType | Import;\n rawFieldType: PrimitiveTypescriptType;\n notNull: boolean;\n derived: \"orm\" | \"sync\" | \"async\" | false;\n protected: boolean;\n unique: boolean;\n superstruct: Import | undefined;\n zodSchema: Import | undefined;\n customSerde: Import | undefined;\n isArray: boolean;\n hasConfigDefault: boolean;\n lazy?: boolean;\n};\n\nexport type EnumField = Field & {\n kind: \"enum\";\n columnName: string;\n columnType: DatabaseColumnType;\n columnDefault: number | boolean | string | null;\n columnGenerated: boolean;\n columnNotNull: boolean;\n derived: \"sync\" | \"async\" | false;\n enumName: string;\n enumType: Import;\n enumDetailType: Import;\n enumDetailsType: Import;\n enumRows: EnumRow[];\n notNull: boolean;\n isArray: boolean;\n hasConfigDefault: boolean;\n};\n\nexport type PgEnumField = Field & {\n kind: \"pg-enum\";\n columnName: string;\n columnDefault: number | boolean | string | null;\n columnGenerated: boolean;\n columnNotNull: boolean;\n /** I.e. `favorite_shape`. */\n dbType: string;\n /** I.e. `FavoriteShape`. */\n enumName: string;\n enumType: Import;\n enumValues: string[];\n notNull: boolean;\n hasConfigDefault: boolean;\n};\n\n/** I.e. a `Book.author` reference pointing to an `Author`. */\nexport type ManyToOneField = Field & {\n kind: \"m2o\";\n columnName: string;\n columnDefault?: number | boolean | string | null;\n columnGenerated: boolean;\n columnNotNull: boolean;\n dbType: string;\n otherFieldName: string;\n otherEntity: Entity;\n notNull: boolean;\n isDeferredAndDeferrable: boolean;\n constraintName: string;\n derived: \"async\" | false;\n hasConfigDefault: boolean;\n onDelete: Action;\n};\n\n/** I.e. a `Author.books` collection. */\nexport type OneToManyField = Field & {\n kind: \"o2m\";\n singularName: string;\n otherEntity: Entity;\n otherFieldName: string;\n otherColumnName: string;\n otherColumnNotNull: boolean;\n isLargeCollection: boolean;\n orderBy: { field: string; direction: \"ASC\" | \"DESC\" } | undefined;\n softDeletes: \"include\" | \"exclude\" | undefined;\n};\n\n/** I.e. a `Author.image` reference when `image.author_id` is unique. */\nexport type OneToOneField = Field & {\n kind: \"o2o\";\n otherEntity: Entity;\n otherFieldName: string;\n otherColumnName: string;\n otherColumnNotNull: boolean;\n};\n\nexport type ManyToManyField = Field & {\n kind: \"m2m\";\n joinTableName: string;\n singularName: string;\n columnName: string;\n otherEntity: Entity;\n otherFieldName: string;\n otherColumnName: string;\n isLargeCollection: boolean;\n isDeferredAndDeferrable: boolean;\n derived: \"async\" | \"otherSide\" | false;\n softDeletes: \"include\" | \"exclude\" | undefined;\n /** Whether the join table has a surrogate `id` PK; if false the FK pair is the composite PK. */\n hasJoinTableId: boolean;\n};\n\n/** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */\nexport type ManyToManyEnumField = Field & {\n kind: \"m2mEnum\";\n joinTableName: string;\n /** The entity's FK column, e.g. `publisher_id`. */\n columnName: string;\n /** The enum's FK column, e.g. `logo_color_id`. */\n otherColumnName: string;\n enumName: string;\n enumType: Import;\n enumDetailType: Import;\n enumDetailsType: Import;\n enumRows: EnumRow[];\n /** Whether the join table has a surrogate `id` PK; if false the FK pair is the composite PK. */\n hasJoinTableId: boolean;\n};\n\n/** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */\nexport type PolymorphicField = Field & {\n kind: \"poly\";\n fieldType: string; // The name of the type union, eg `CommentParent`\n notNull: boolean;\n hasConfigDefault: boolean;\n components: PolymorphicFieldComponent[];\n};\n\nexport type PolymorphicFieldComponent = {\n columnName: string; // eg `parent_book_id` or `parent_book_review_id`\n otherFieldName: string; // eg `comment` or `comments`\n otherEntity: Entity;\n isDeferredAndDeferrable: boolean;\n constraintName: string;\n notNull: false; // Added to structurally match ManyToOneField\n};\n\nexport type FieldNameOverrides = {\n fieldName?: string;\n otherFieldName?: string;\n};\n\n/** Adapts the generally-great pg-structure metadata into our specific ORM types. */\nexport class EntityDbMetadata {\n entity: Entity;\n primaryKey: PrimitiveField;\n primitives: PrimitiveField[];\n enums: EnumField[];\n pgEnums: PgEnumField[];\n manyToOnes: ManyToOneField[];\n oneToManys: OneToManyField[];\n largeOneToManys: OneToManyField[];\n oneToOnes: OneToOneField[];\n manyToManys: ManyToManyField[];\n largeManyToManys: ManyToManyField[];\n manyToManyEnums: ManyToManyEnumField[];\n polymorphics: PolymorphicField[];\n tableName: string;\n tagName: string;\n createdAt: PrimitiveField | undefined;\n updatedAt: PrimitiveField | undefined;\n deletedAt: PrimitiveField | undefined;\n baseClassName: string | undefined;\n baseType: EntityDbMetadata | undefined;\n subTypes: EntityDbMetadata[] = [];\n inheritanceType: \"sti\" | \"cti\" | undefined;\n /** This will only be set on the base meta. */\n stiDiscriminatorField?: string;\n /** This will only be set on the sub metas. */\n stiDiscriminatorValue?: number;\n abstract: boolean;\n nonDeferredFkOrder: number = -1;\n uniqueConstraints?: string[][];\n /** Gates mutation targets, not reads; false when required columns or array storage have no supported mutation mapping. */\n supportsEmExecute?: boolean;\n /** Original table fields, captured before inheritance partitions or specializes them. */\n physicalMetadata?: EntityDbMetadata;\n\n constructor(config: Config, table: Table, enums: EnumMetadata = {}) {\n this.entity = makeEntity(tableToEntityName(config, table));\n\n if (isSubClassTable(table)) {\n this.baseClassName = tableToEntityName(config, table.columns.get(\"id\").foreignKeys[0].referencedTable);\n this.inheritanceType = \"cti\";\n }\n\n this.primaryKey =\n table.columns\n .filter((c) => c.isPrimaryKey)\n .map((column) => newPrimitive(config, this.entity, column, table))[0] ||\n fail(`No primary key found for ${table.name}`);\n\n this.primitives = table.columns\n .filter((c) => !c.isPrimaryKey && !c.isForeignKey)\n .filter((c) => !isEnumArray(c) && !isPgEnum(c))\n .map((column) => newPrimitive(config, this.entity, column, table))\n .filter((f) => !f.ignore);\n\n this.enums = [\n ...table.m2oRelations\n .filter((r) => isEnumTable(config, r.targetTable))\n .map((r) => newEnumField(config, this.entity, r, enums))\n .filter((f) => !f.ignore),\n ...table.columns\n .filter((c) => isEnumArray(c))\n .map((column) => newEnumArrayField(config, this.entity, column, enums))\n .filter((f) => !f.ignore),\n ];\n this.pgEnums = table.columns\n .filter((c) => isPgEnum(c))\n .map((column) => newPgEnumField(config, this.entity, column))\n .filter((f) => !f.ignore);\n\n this.manyToOnes = table.m2oRelations\n .filter((r) => !isEnumTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => !isComponentOfPolymorphicRelation(config, r))\n .filter((r) => !isBaseClassForeignKey(r))\n .map((r) => newManyToOneField(config, this.entity, r))\n .filter((f) => !f.ignore);\n\n // We split these into regular/large...\n const allOneToManys = table.o2mRelations\n // ManyToMany join tables also show up as OneToMany tables in pg-structure\n .filter((r) => !isJoinTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => !isOneToOneRelation(r))\n .map((r) => newOneToMany(config, this.entity, r))\n // Do not generate o2m for ReactiveReferences\n .filter((f) => !isReactiveReference(config, f.otherEntity, f.otherFieldName))\n .filter((f) => !f.ignore);\n this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);\n this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);\n\n this.oneToOnes = table.o2mRelations\n // ManyToMany join tables also show up as OneToMany tables in pg-structure\n .filter((r) => !isJoinTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => !isBaseClassForeignKey(r))\n .filter((r) => isOneToOneRelation(r))\n .map((r) => newOneToOne(config, this.entity, r))\n .filter((f) => !f.ignore);\n\n // We split these into regular/large\n const allManyToManys = table.m2mRelations\n // pg-structure is really loose on what it considers a m2m relationship, i.e. any entity\n // that has a foreign key to us, and a foreign key to something else, is automatically\n // considered as a join table/m2m between \"us\" and \"something else\". Filter these out\n // by looking for only true join tables, i.e. tables with only id, fk1, and fk2.\n .filter((r) => isJoinTable(config, r.joinTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n // Join tables whose \"other\" side is an enum table become EnumCollections instead.\n .filter((r) => !isEnumTable(config, r.targetTable))\n .map((r) => newManyToManyField(config, this.entity, r))\n .filter((f) => !f.ignore);\n this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);\n this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);\n\n // A join table between us and an enum table, i.e. `Publisher.logoColors`.\n this.manyToManyEnums = table.m2mRelations\n .filter((r) => isJoinTable(config, r.joinTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => isEnumTable(config, r.targetTable))\n .map((r) => newManyToManyEnumField(config, this.entity, r, enums))\n .filter((f) => !f.ignore);\n\n this.polymorphics = polymorphicRelations(config, table).map((rc) =>\n newPolymorphicField(config, table, this.entity, rc),\n );\n\n this.tableName = table.name;\n this.tagName = config.entities[this.entity.name]?.tag;\n this.abstract = config.entities[this.entity.name]?.abstract || false;\n\n const { createdAtConf, updatedAtConf, deletedAtConf } = getTimestampConfig(config);\n this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));\n this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));\n this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));\n this.uniqueConstraints = inferUniqueConstraints(this, table);\n const fields = [this.primaryKey, ...this.primitives, ...this.enums, ...this.pgEnums, ...this.manyToOnes];\n const mapped = new Set(fields.map((field) => field.columnName));\n // Composite keys and unmapped NOT NULL columns cannot be supplied through mutation field names.\n this.supportsEmExecute =\n table.primaryKey?.columns.length === 1 &&\n this.primaryKey.columnName === \"id\" &&\n // Native enum and multidimensional arrays still have scalar field mappings.\n table.columns.every((column) => column.arrayDimension <= 1 && !(isArray(column) && isPgEnum(column))) &&\n // JSON/schema serdes encode one JSON value, not a SQL array. Date-mode serdes also encode one scalar.\n // Custom element mappers and Temporal array serdes have separate elementwise write paths.\n !this.primitives.some(\n (field) =>\n field.isArray &&\n !field.customSerde &&\n (field.columnType === \"jsonb\" ||\n (!config.temporal &&\n (field.columnType === \"date\" ||\n field.columnType === \"timestamp with time zone\" ||\n field.columnType === \"timestamp without time zone\"))),\n ) &&\n table.columns.every(\n (column) =>\n mapped.has(column.name) || !column.notNull || column.defaultWithTypeCast !== null || column.isGenerated,\n );\n }\n\n get name(): string {\n return this.entity.name;\n }\n\n get nonDeferredFks(): Array<ManyToOneField | PolymorphicFieldComponent> {\n return [\n ...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable),\n ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable),\n ];\n }\n\n get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n }\n}\n\nfunction isMultiColumnForeignKey(r: M2ORelation | O2MRelation | M2MRelation) {\n return r.foreignKey.columns.length > 1;\n}\n\nfunction isBaseClassForeignKey(r: M2ORelation | O2MRelation | M2MRelation) {\n return r.foreignKey.columns.length === 1 && r.foreignKey.columns[0].name === \"id\";\n}\n\nfunction isOneToOneRelation(r: O2MRelation) {\n // otherColumn will be the images.book_id in the other table\n const otherColumn = r.foreignKey.columns[0];\n // r.foreignKey.index is the index on _us_ (i.e. our Book primary key), so look up indexes in the target table\n const indexes = r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || [];\n return indexes.find(isOneToOneIndex) !== undefined;\n}\n\n// If the unique index has only one column and is NOT a partial index, it's a one-to-one\nfunction isOneToOneIndex(i: Index) {\n return i.columns.length === 1 && !i.isPartial;\n}\n\n/** Infers field names from unique constraints, i.e. `(author_id, title)` becomes `author, title`. */\nfunction inferUniqueConstraints(meta: EntityDbMetadata, table: Table): string[][] {\n return table.uniqueConstraints.flatMap((constraint) => {\n if (constraint.index.isPartial) return [];\n const fields = Array.from(constraint.columns).map((column) => fieldNameForColumn(meta, column.name));\n if (fields.some((field) => field === undefined)) return [];\n return [fields as string[]];\n });\n}\n\n/** Returns the queryable field name for a unique constraint column. */\nfunction fieldNameForColumn(meta: EntityDbMetadata, columnName: string): string | undefined {\n const primitive = meta.primitives.find((field) => field.columnName === columnName);\n if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde) return primitive.fieldName;\n\n const enumField = meta.enums.find((field) => field.columnName === columnName);\n if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;\n\n const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);\n if (pgEnum) return pgEnum.fieldName;\n\n const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);\n if (manyToOne && !manyToOne.derived) return manyToOne.fieldName;\n\n return undefined;\n}\n\ntype PolymorphicRelation = { fieldName: string; notNull: boolean };\nfunction polymorphicRelations(config: Config, table: Table): PolymorphicRelation[] {\n const entity = config.entities[tableToEntityName(config, table)];\n return Object.entries(entity?.relations ?? {})\n .filter(([, r]) => r.polymorphic)\n .map(([fieldName, { polymorphic }]) => ({ fieldName, notNull: polymorphic === \"notNull\" }));\n}\n\nfunction polymorphicFieldName(config: Config, r: M2ORelation | O2MRelation) {\n const { name } = r.foreignKey.columns[0];\n const table = r.type === \"m2o\" ? r.sourceTable : r.targetTable;\n return polymorphicRelations(config, table).find((pr) => name.startsWith(`${snakeCase(pr.fieldName)}_`))?.fieldName;\n}\n\nfunction isComponentOfPolymorphicRelation(config: Config, r: M2ORelation) {\n return polymorphicFieldName(config, r) !== undefined;\n}\n\nfunction determineUserType(\n fieldType: PrimitiveTypescriptType,\n superstruct: string | undefined,\n zodSchema: string | undefined,\n userFieldType: string | undefined,\n) {\n if (fieldType === \"Object\" && superstruct) {\n return superstructType(superstruct);\n }\n\n if (fieldType === \"Object\" && zodSchema) {\n return zodSchemaType(zodSchema);\n }\n\n if (userFieldType) {\n return userFieldTypeType(userFieldType);\n }\n\n return fieldType;\n}\n\nfunction newPrimitive(config: Config, entity: Entity, column: Column, table: Table): PrimitiveField {\n const fieldName = primitiveFieldName(column.name);\n const columnName = column.name;\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const array = isArray(column);\n const fieldType = mapType(config, table.name, columnName, columnType);\n const customSerde = serdeConfig(config, entity, fieldName);\n const superstruct = superstructConfig(config, entity, fieldName);\n const zodSchema = zodSchemaConfig(config, entity, fieldName);\n const userFieldType = fieldTypeConfig(config, entity, fieldName);\n const maybeUserType = determineUserType(fieldType, superstruct, zodSchema, userFieldType);\n const unique = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"primitive\",\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnType,\n fieldType: array ? code`${maybeUserType}[]` : maybeUserType,\n rawFieldType: fieldType,\n notNull: column.notNull,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: fieldDerived(config, entity, fieldName),\n protected: isProtected(config, entity, fieldName),\n unique,\n ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),\n superstruct: fieldType === \"Object\" && superstruct ? Import.from(superstruct) : undefined,\n zodSchema: fieldType === \"Object\" && zodSchema ? Import.from(zodSchema) : undefined,\n customSerde: customSerde ? serdeType(customSerde) : undefined,\n isArray: array,\n hasConfigDefault, // can be set to true by scanEntityFiles\n lazy: isLazyField(config, entity, fieldName),\n };\n}\n\nfunction fieldDerived(config: Config, entity: Entity, fieldName: string): PrimitiveField[\"derived\"] {\n if (ormMaintainedFields.includes(fieldName)) {\n return \"orm\";\n } else if (isGetterField(config, entity, fieldName)) {\n return \"sync\";\n } else if (isReactiveField(config, entity, fieldName)) {\n return \"async\";\n } else {\n return false;\n }\n}\n\nfunction fkFieldDerived(config: Config, entity: Entity, fieldName: string): ManyToOneField[\"derived\"] {\n if (isReactiveReference(config, entity, fieldName)) {\n return \"async\";\n } else {\n return false;\n }\n}\n\nfunction newEnumField(config: Config, entity: Entity, r: M2ORelation, enums: EnumMetadata): EnumField {\n const column = r.foreignKey.columns[0];\n const columnName = column.name;\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const fieldName = enumFieldName(column.name);\n const enumName = tableToEntityName(config, r.targetTable);\n const enumType = imp(`${enumName}@./entities.ts`);\n const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);\n const enumDetailsType = imp(`${enumName}Details@./entities.ts`);\n const notNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"enum\",\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnType,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: fieldDerived(config, entity, fieldName) as EnumField[\"derived\"],\n enumName,\n enumType,\n enumDetailType,\n enumDetailsType,\n notNull,\n ignore,\n enumRows: enums[r.targetTable.name].rows,\n isArray: false,\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newEnumArrayField(config: Config, entity: Entity, column: Column, enums: EnumMetadata): EnumField {\n const columnName = column.name;\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const fieldName = enumFieldName(column.name);\n // Find the enum table name via the comment hint (instead of a FK constraint), and strip the enum= prefix\n const enumTable = column.comment!.replace(\"enum=\", \"\");\n const enumName = (enums[enumTable] || fail(`Could not find enum ${enumTable}`)).name;\n const enumType = imp(`${enumName}@./entities.ts`);\n const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);\n const enumDetailsType = imp(`${enumName}Details@./entities.ts`);\n const notNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"enum\",\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnType,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: fieldDerived(config, entity, fieldName) as EnumField[\"derived\"],\n enumName,\n enumType,\n enumDetailType,\n enumDetailsType,\n notNull,\n ignore,\n enumRows: enums[enumTable].rows,\n isArray: true,\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newPgEnumField(config: Config, entity: Entity, column: Column): PgEnumField {\n const fieldName = primitiveFieldName(column.name);\n const columnName = column.name;\n const enumName = pascalCase(column.type.name);\n const enumType = imp(`${enumName}@./entities.ts`);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"pg-enum\",\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n dbType: column.type.name,\n enumType,\n enumName,\n enumValues: (column.type as EnumType).values,\n notNull: column.notNull,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newManyToOneField(config: Config, entity: Entity, r: M2ORelation): ManyToOneField {\n const column = r.foreignKey.columns[0];\n const columnName = column.name;\n const dbType = r.foreignKey.columns[0].type.shortName!;\n const fieldName = referenceName(config, entity, r);\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const isOneToOne = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;\n const otherFieldName = isOneToOne\n ? oneToOneName(config, otherEntity, entity, r)\n : collectionName(config, otherEntity, entity, r).fieldName;\n const notNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);\n const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;\n const derived = fkFieldDerived(config, entity, fieldName);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"m2o\",\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n otherEntity,\n otherFieldName,\n notNull,\n ignore,\n derived,\n dbType,\n isDeferredAndDeferrable,\n constraintName: r.foreignKey.name,\n hasConfigDefault, // can be set to true by scanEntityFiles\n onDelete: r.foreignKey.onDelete,\n };\n}\n\nfunction newOneToMany(config: Config, entity: Entity, r: O2MRelation): OneToManyField {\n const column = r.foreignKey.columns[0];\n // source == parent i.e. the reference of the foreign key column\n // target == child i.e. the table with the foreign key column in it\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const { singularName, fieldName } = collectionName(config, entity, otherEntity, r);\n const otherFieldName = referenceName(config, otherEntity, r);\n const orderBy =\n config.entities[entity.name]?.relations?.[fieldName]?.orderBy ?? config.entities[otherEntity.name]?.orderBy;\n return {\n kind: \"o2m\",\n fieldName,\n singularName,\n otherEntity,\n otherFieldName,\n otherColumnName: column.name,\n otherColumnNotNull: column.notNull,\n ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),\n isLargeCollection: isLargeCollection(config, entity, fieldName),\n orderBy: parseOrder(orderBy),\n softDeletes: softDeletesConfig(config, entity, fieldName),\n };\n}\n\nfunction newOneToOne(config: Config, entity: Entity, r: O2MRelation): OneToOneField {\n const column = r.foreignKey.columns[0];\n // source == parent i.e. the reference of the foreign key column\n // target == child i.e. the table with the foreign key column in it\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const fieldName = oneToOneName(config, entity, otherEntity, r);\n const otherFieldName = referenceName(config, otherEntity, r);\n const otherColumnName = column.name;\n const otherColumnNotNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName);\n return { kind: \"o2o\", fieldName, otherEntity, otherFieldName, otherColumnName, otherColumnNotNull, ignore };\n}\n\nfunction newManyToManyField(config: Config, entity: Entity, r: M2MRelation): ManyToManyField {\n const { foreignKey, targetForeignKey, targetTable } = r;\n const otherEntity = makeEntity(tableToEntityName(config, targetTable));\n // For foo_to_bar.some_foo_id use the `some_foo_id` column i.e. `someFoos`\n const fieldName = manyToManyName(targetForeignKey.columns[0]);\n const otherFieldName = manyToManyName(foreignKey.columns[0]);\n const isDeferredAndDeferrable = targetForeignKey.isDeferred && targetForeignKey.isDeferrable;\n\n // Determine if this m2m is derived:\n // - \"async\" if this side is explicitly marked as a ReactiveManyToMany\n // - \"otherSide\" if the OTHER side is marked as a ReactiveManyToMany (making this the read-only other side)\n // - false otherwise (regular m2m)\n const isThisSideDerived = isReactiveManyToMany(config, entity, fieldName);\n const isOtherSideDerived = isReactiveManyToMany(config, otherEntity, otherFieldName);\n const derived = isThisSideDerived ? \"async\" : isOtherSideDerived ? \"otherSide\" : false;\n\n return {\n kind: \"m2m\",\n joinTableName: r.joinTable.name,\n fieldName,\n singularName: singular(fieldName),\n columnName: foreignKey.columns[0].name,\n otherEntity,\n otherFieldName,\n otherColumnName: targetForeignKey.columns[0].name,\n ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),\n isLargeCollection: isLargeCollection(config, entity, fieldName),\n isDeferredAndDeferrable,\n derived,\n softDeletes: softDeletesConfig(config, entity, fieldName),\n hasJoinTableId: joinTableHasId(r.joinTable),\n };\n}\n\nfunction newManyToManyEnumField(\n config: Config,\n entity: Entity,\n r: M2MRelation,\n enums: EnumMetadata,\n): ManyToManyEnumField {\n const { foreignKey, targetForeignKey, targetTable } = r;\n // For publisher_logo_colors.logo_color_id use the `logo_color_id` column i.e. `logoColors`\n const fieldName = manyToManyName(targetForeignKey.columns[0]);\n const enumName = tableToEntityName(config, targetTable);\n return {\n kind: \"m2mEnum\",\n joinTableName: r.joinTable.name,\n fieldName,\n columnName: foreignKey.columns[0].name,\n otherColumnName: targetForeignKey.columns[0].name,\n enumName,\n enumType: imp(`${enumName}@./entities.ts`),\n enumDetailType: imp(`${plural(enumName)}@./entities.ts`),\n enumDetailsType: imp(`${enumName}Details@./entities.ts`),\n enumRows: enums[targetTable.name].rows,\n ignore: isFieldIgnored(config, entity, fieldName),\n hasJoinTableId: joinTableHasId(r.joinTable),\n };\n}\n\nfunction newPolymorphicField(config: Config, table: Table, entity: Entity, pr: PolymorphicRelation) {\n const { fieldName, notNull } = pr;\n const components = table.m2oRelations\n .filter((r) => !isEnumTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => polymorphicFieldName(config, r) === fieldName)\n .map((r) => newPolymorphicFieldComponent(config, entity, r));\n const fieldType = `${entity.name}${pascalCase(fieldName)}`;\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"poly\" as const,\n fieldName,\n fieldType,\n notNull,\n components,\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newPolymorphicFieldComponent(config: Config, entity: Entity, r: M2ORelation): PolymorphicFieldComponent {\n const column = r.foreignKey.columns[0];\n const columnName = column.name;\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const isOneToOne = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;\n const otherFieldName = isOneToOne\n ? oneToOneName(config, otherEntity, entity, r)\n : collectionName(config, otherEntity, entity, r).fieldName;\n const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;\n return {\n columnName,\n otherEntity,\n otherFieldName,\n isDeferredAndDeferrable,\n constraintName: r.foreignKey.name,\n notNull: false,\n };\n}\n\nfunction isFieldNameOverrides(maybeOverride: JSONData | undefined): maybeOverride is FieldNameOverrides {\n return (\n maybeOverride !== null &&\n !Array.isArray(maybeOverride) &&\n typeof maybeOverride === \"object\" &&\n Object.keys(maybeOverride).some((k) => k === \"fieldName\" || k === \"otherFieldName\")\n );\n}\n\n/** Finds the field name for o2o side of a o2o/m2o. */\nexport function oneToOneName(\n config: Config,\n // I.e. the Book for o2o Book.image <-- `images.book_id`\n refEntity: Entity,\n // I.e. the Image for o2o Book.image <-- `images.book_id`\n keyEntity: Entity,\n r: M2ORelation | O2MRelation,\n): string {\n // If the name is overridden then use that\n const overrides = r.foreignKey.columns[0].commentData;\n if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {\n return overrides.otherFieldName;\n }\n // For `comments.parent_book_review_id`, we would just use `BookReview.comment` as the name\n // For `authors.draft_current_book_id`, we would just use `Book.author` as the name\n // For `project_items.current_selection_id`, we would use `HomeownerSelection.currentProjectItem`\n const refTable = r instanceof M2ORelation ? r.targetTable : r.sourceTable;\n // Does the ref table have any m2o pointing table at the key table?\n const found = refTable.m2oRelations.find((s) => tableToEntityName(config, s.targetTable) === keyEntity.name);\n // console.log({refTable: refTable.name, keyTable: keyTable.name, found: found?.name, fieldName});\n if (!found) {\n // If there aren't any m2os, just use the raw type name like `.image` or `.comment`\n return camelCase(keyEntity.name);\n } else {\n // If there is a m2o, assume we might conflict, and use the column name to at least be unique\n // Start with `book` from `images.book_id` or `current_draft_book` from `authors.current_draft_book_id`\n let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, \"\");\n // Suffix the new type that we're pointing to, to `current_draft_book_author`\n fieldName = `${fieldName}_${keyEntity.name}`;\n // And drop the `book`, to `current_draft__author`\n fieldName = fieldName.replace(refEntity.name.toLowerCase(), \"\");\n // Then camel case, to `currentDraftAuthor`\n return camelCase(fieldName);\n }\n}\n\nconst idSuffix = /_id$|Id$/;\n\nexport function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string {\n const [column] = r.foreignKey.columns;\n const overrides = column.commentData;\n return (\n polymorphicFieldName(config, r) ??\n // If the name is overridden then use that\n (isFieldNameOverrides(overrides) ? overrides.fieldName : undefined) ??\n camelCase(column.name.replace(idSuffix, \"\"))\n );\n}\n\nfunction enumFieldName(columnName: string) {\n return camelCase(columnName.replace(idSuffix, \"\"));\n}\n\nfunction primitiveFieldName(columnName: string) {\n return camelCase(columnName);\n}\n\nexport function manyToManyName(column: Column) {\n const overrides = column.commentData;\n // If the name is overridden then use that\n if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {\n return overrides.otherFieldName;\n }\n return camelCase(plural(column.name.replace(idSuffix, \"\")));\n}\n\n/** Returns the collection name to use on `entity` when referring to `otherEntity`s. */\nexport function collectionName(\n config: Config,\n // I.e. the Author for o2m Author.books --> books.author_id\n singleEntity: Entity,\n // I.e. the Book for o2m Author.books --> books.author_id\n collectionEntity: Entity,\n r: M2ORelation | O2MRelation | M2MRelation,\n): { fieldName: string; singularName: string } {\n const [column] = r.foreignKey.columns;\n const overrides = column.commentData;\n // If the name is overridden then use that, but also singularize it\n if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {\n const fieldName = overrides.otherFieldName;\n return { fieldName, singularName: singular(fieldName) };\n }\n // I.e. if the m2o is `books.author_id`, use `Author.books` as the collection name (we pluralize at the end).\n let singularName = collectionEntity.name;\n // Check if we have multiple FKs from collectionEntity --> singleEntity and prefix with FK name if so\n const sourceTable = r.type === \"m2o\" ? r.sourceTable : r.targetTable;\n const targetTable = r.type === \"m2o\" ? r.targetTable : r.sourceTable;\n // If `books.foo_author_id` and `books.bar_author_id` both exist\n if (r.type !== \"m2m\" && sourceTable.m2oRelations.filter((r) => r.targetTable === targetTable).length > 1) {\n // Use `fooAuthorBooks`, `barAuthorBooks`\n singularName = `${column.name.replace(idSuffix, \"\")}_${singularName}`;\n }\n // If we've guessed `Book.bookReviews` based on `book_reviews.book_id` --> `bookReviews`, strip the `Book` prefix\n if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) {\n singularName = singularName.substring(singleEntity.name.length);\n }\n // camelize the name\n singularName = camelCase(singularName);\n // and pluralize for fieldName\n return { fieldName: plural(singularName), singularName };\n}\n\nexport function failIfOverlappingFieldNames(entity: EntityDbMetadata): void {\n const allFields = [\n entity.primaryKey,\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.oneToManys,\n ...entity.largeOneToManys,\n ...entity.oneToOnes,\n ...entity.manyToManys,\n ...entity.largeManyToManys,\n ...entity.manyToManyEnums,\n ...entity.polymorphics,\n ];\n Object.entries(groupBy(allFields, (f) => f.fieldName)).forEach(([fieldName, fields]) => {\n if (fields.length > 1) {\n throw new Error(\n `In ${entity.name}, found multiple fields named '${fieldName}': ${fields.map((f) => f.kind).join(\" \")}`,\n );\n }\n });\n}\n\nexport function makeEntity(entityName: string): Entity {\n // Default to the conventional names; `resolveNameConflicts` rewrites them if they collide.\n const names = entitySymbolNames(entityName);\n return {\n name: entityName,\n type: entityType(entityName),\n typeSymbol: entityTypeSymbol(entityName),\n typeForMetadataFile: entityTypeForMetadataFile(entityName),\n metaName: metaName(entityName),\n metaType: metaType(entityName),\n idType: entityTypeImport(entityName, names.idName),\n orderType: entityTypeImport(entityName, names.orderName),\n optsType: entityTypeImport(entityName, names.optsName),\n configConst: imp(`${camelCase(entityName)}Config@./entities.ts`, {\n definedIn: `./codegen/${entityName}Codegen.ts`,\n }),\n ...names,\n };\n}\n\n/**\n * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.\n *\n * `makeEntity` mints a fresh `Entity` for every relation's `otherEntity`, so each entity ends up with\n * many duplicate objects floating around. Pointing them all at the single `entitiesByName[name].entity`\n * instance means later passes (i.e. `resolveNameConflicts`) only have to update one object per name.\n *\n * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.\n */\nexport function canonicalizeOtherEntities(db: DbMetadata): void {\n const canonical = (other: Entity) => db.entitiesByName[other.name]?.entity ?? other;\n for (const meta of db.entities) {\n for (const field of [\n ...meta.manyToOnes,\n ...meta.oneToManys,\n ...meta.largeOneToManys,\n ...meta.oneToOnes,\n ...meta.manyToManys,\n ...meta.largeManyToManys,\n ]) {\n field.otherEntity = canonical(field.otherEntity);\n }\n for (const poly of meta.polymorphics) {\n for (const comp of poly.components) comp.otherEntity = canonical(comp.otherEntity);\n }\n if (meta.physicalMetadata) {\n canonicalizeOtherEntities({ ...db, entities: [meta.physicalMetadata] });\n }\n }\n}\n\n/**\n * Rewrites codegen'd type names that collide with another exported type name.\n *\n * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or\n * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name\n * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.\n *\n * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates\n * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).\n */\nexport function resolveNameConflicts(config: Config, db: DbMetadata): void {\n // The names exported into `entities.ts` that a codegen'd type could shadow.\n const reserved = new Set<string>(db.entities.map((meta) => meta.name));\n for (const enumData of Object.values(db.enums)) {\n // An enum table exports its (singularized) type, its `Details` type/const, and its pluralized const,\n // i.e. `ChangeRequestAssetScope`, `ChangeRequestAssetScopeDetails`, and `ChangeRequestAssetScopes`.\n const enumName = tableToEntityName(config, enumData.table);\n reserved.add(enumName).add(`${enumName}Details`).add(plural(enumName));\n }\n for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);\n for (const meta of db.entities) {\n if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);\n }\n}\n\n/** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */\nfunction entitySymbolNames(name: string, reserved?: Set<string>) {\n const pick = (suffix: string) => (reserved?.has(`${name}${suffix}`) ? `${name}_${suffix}` : `${name}${suffix}`);\n return {\n idName: pick(\"Id\"),\n fieldsName: pick(\"Fields\"),\n optsName: pick(\"Opts\"),\n idsOptsName: pick(\"IdsOpts\"),\n filterName: pick(\"Filter\"),\n graphqlFilterName: pick(\"GraphQLFilter\"),\n orderName: pick(\"Order\"),\n factoryExtrasName: pick(\"FactoryExtras\"),\n scopeName: pick(\"Scope\"),\n scopesName: pick(\"Scopes\"),\n };\n}\n\n/** Returns true if any of the entity's conventional type names is already taken. */\nfunction hasNameConflict(name: string, reserved: Set<string>): boolean {\n return Object.values(entitySymbolNames(name)).some((conventional) => reserved.has(conventional));\n}\n\n/** Rewrites an entity's type names (and the `Import`s built from them) to their de-conflicted form. */\nfunction applyEntityNames(entity: Entity, reserved: Set<string>): void {\n const names = entitySymbolNames(entity.name, reserved);\n Object.assign(entity, names);\n entity.idType = entityTypeImport(entity.name, names.idName);\n entity.orderType = entityTypeImport(entity.name, names.orderName);\n entity.optsType = entityTypeImport(entity.name, names.optsName);\n}\n\nfunction entityTypeImport(entityName: string, symbolName: string): Import {\n return imp(`t:${symbolName}@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` });\n}\n\nfunction metaName(entityName: string): string {\n return `${camelCase(entityName)}Meta`;\n}\n\nfunction metaType(entityName: string): Import {\n return imp(`${metaName(entityName)}@./entities.ts`);\n}\n\nfunction entityType(entityName: string): Import {\n return imp(`t:${entityName}@./entities.ts`);\n}\n\nfunction entityTypeSymbol(entityName: string): Import {\n return imp(`${entityName}@./entities.ts`);\n}\n\nfunction entityTypeForMetadataFile(entityName: string): Import {\n return imp(`${entityName}@./${entityName}.ts`);\n}\n\nfunction mapType(\n config: Config,\n tableName: string,\n columnName: string,\n dbColumnType: DatabaseColumnType,\n): PrimitiveTypescriptType {\n return mapSimpleDbTypeToTypescriptType(config, dbColumnType);\n}\n\nfunction isEnumArray(c: Column): boolean {\n return c.arrayDimension === 1 && !!c.comment && c.comment.startsWith(\"enum=\");\n}\n\nfunction isArray(c: Column): boolean {\n return c.arrayDimension === 1;\n}\n\nfunction isPgEnum(c: Column): boolean {\n return c.type instanceof EnumType;\n}\n\nfunction superstructType(s: string): Import {\n // Assume it's `foo@...`, turn it into `Foo@...`\n const [symbol, ...path] = s.split(\"@\");\n return Import.from(`${pascalCase(symbol)}@${path.join(\"@\")}`);\n}\n\nfunction zodSchemaType(s: string): Code {\n const schema = Import.from(s);\n return code`${Zod}.input<typeof ${schema}>`;\n}\n\nfunction userFieldTypeType(s: string): Import {\n return Import.from(`t:${s}`);\n}\n\nfunction serdeType(s: string): Import {\n return Import.from(s);\n}\n"],"mappings":";;;;;;;;;;;;;AAgDA,MAAM,EAAE,QAAQ,aAAa,UAAA;;AA6P7B,IAAa,mBAAb,MAA8B;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,WAA+B,CAAC;CAChC;;CAEA;;CAEA;CACA;CACA,qBAA6B;CAC7B;;CAEA;;CAEA;CAEA,YAAY,QAAgB,OAAc,QAAsB,CAAC,GAAG;EAClE,KAAK,SAAS,WAAWA,cAAAA,kBAAkB,QAAQ,KAAK,CAAC;EAEzD,IAAIC,cAAAA,gBAAgB,KAAK,GAAG;GAC1B,KAAK,gBAAgBD,cAAAA,kBAAkB,QAAQ,MAAM,QAAQ,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC,eAAe;GACrG,KAAK,kBAAkB;EACzB;EAEA,KAAK,aACH,MAAM,QACH,QAAQ,MAAM,EAAE,YAAY,CAAC,CAC7B,KAAK,WAAW,aAAa,QAAQ,KAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,MACrEE,cAAAA,KAAK,4BAA4B,MAAM,MAAM;EAE/C,KAAK,aAAa,MAAM,QACrB,QAAQ,MAAM,CAAC,EAAE,gBAAgB,CAAC,EAAE,YAAY,CAAC,CACjD,QAAQ,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAC9C,KAAK,WAAW,aAAa,QAAQ,KAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,CACjE,QAAQ,MAAM,CAAC,EAAE,MAAM;EAE1B,KAAK,QAAQ,CACX,GAAG,MAAM,aACN,QAAQ,MAAMC,cAAAA,YAAY,QAAQ,EAAE,WAAW,CAAC,CAAC,CACjD,KAAK,MAAM,aAAa,QAAQ,KAAK,QAAQ,GA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,YAA4B;CAC9C,QAAA,GAAOA,QAAAA,IAAAA,CAAI,KAAK,WAAW,eAAe;AAC5C;AAEA,SAAS,iBAAiB,YAA4B;CACpD,QAAA,GAAOA,QAAAA,IAAAA,CAAI,GAAG,WAAW,eAAe;AAC1C;AAEA,SAAS,0BAA0B,YAA4B;CAC7D,QAAA,GAAOA,QAAAA,IAAAA,CAAI,GAAG,WAAW,KAAK,WAAW,IAAI;AAC/C;AAEA,SAAS,QACP,QACA,WACA,YACA,cACyB;CACzB,OAAOU,cAAAA,gCAAgC,QAAQ,YAAY;AAC7D;AAEA,SAAS,YAAY,GAAoB;CACvC,OAAO,EAAE,mBAAmB,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,WAAW,OAAO;AAC9E;AAEA,SAAS,QAAQ,GAAoB;CACnC,OAAO,EAAE,mBAAmB;AAC9B;AAEA,SAAS,SAAS,GAAoB;CACpC,OAAO,EAAE,gBAAgBC,aAAAA;AAC3B;AAEA,SAAS,gBAAgB,GAAmB;CAE1C,MAAM,CAAC,QAAQ,GAAG,QAAQ,EAAE,MAAM,GAAG;CACrC,OAAOhB,QAAAA,OAAO,KAAK,IAAA,GAAGM,YAAAA,WAAAA,CAAW,MAAM,EAAE,GAAG,KAAK,KAAK,GAAG,GAAG;AAC9D;AAEA,SAAS,cAAc,GAAiB;CACtC,MAAM,SAASN,QAAAA,OAAO,KAAK,CAAC;CAC5B,OAAO,QAAA,IAAI,GAAGiB,gBAAAA,IAAI,gBAAgB,OAAO;AAC3C;AAEA,SAAS,kBAAkB,GAAmB;CAC5C,OAAOjB,QAAAA,OAAO,KAAK,KAAK,GAAG;AAC7B;AAEA,SAAS,UAAU,GAAmB;CACpC,OAAOA,QAAAA,OAAO,KAAK,CAAC;AACtB"}
1
+ {"version":3,"file":"EntityDbMetadata.cjs","names":["tableToEntityName","isSubClassTable","fail","isEnumTable","isJoinTable","isReactiveReference","getTimestampConfig","snakeCase","serdeConfig","superstructConfig","zodSchemaConfig","fieldTypeConfig","isFieldHasDefault","isProtected","isFieldIgnored","Import","isLazyField","ormMaintainedFields","isGetterField","isReactiveField","imp","pascalCase","isLargeCollection","parseOrder","softDeletesConfig","isReactiveManyToMany","joinTableHasId","M2ORelation","camelCase","groupBy","mapSimpleDbTypeToTypescriptType","EnumType","Zod"],"sources":["../src/EntityDbMetadata.ts"],"sourcesContent":["import { camelCase, pascalCase, snakeCase } from \"change-case\";\nimport { groupBy } from \"joist-utils\";\nimport {\n type Action,\n type Column,\n EnumType,\n type Index,\n type JSONData,\n type M2MRelation,\n M2ORelation,\n type O2MRelation,\n type Table,\n} from \"pg-structure\";\nimport pluralize from \"pluralize\";\nimport { type Code, Import, code, imp } from \"ts-poet\";\n\nimport {\n type Config,\n fieldTypeConfig,\n getTimestampConfig,\n isFieldHasDefault,\n isFieldIgnored,\n isGetterField,\n isLargeCollection,\n isLazyField,\n isProtected,\n isReactiveField,\n isReactiveManyToMany,\n isReactiveReference,\n ormMaintainedFields,\n serdeConfig,\n softDeletesConfig,\n superstructConfig,\n zodSchemaConfig,\n} from \"./config.ts\";\nimport { type EnumMetadata, type EnumRow, type PgEnumMetadata } from \"./loadMetadata.ts\";\nimport { Zod } from \"./symbols.ts\";\nimport {\n fail,\n isEnumTable,\n isJoinTable,\n isSubClassTable,\n joinTableHasId,\n mapSimpleDbTypeToTypescriptType,\n parseOrder,\n tableToEntityName,\n} from \"./utils.ts\";\n\nconst { plural, singular } = pluralize;\n\n/** All the entities + enums in our database. */\nexport interface DbMetadata {\n entities: EntityDbMetadata[];\n /** Type name i.e. `Author` to metadata. */\n entitiesByName: Record<string, EntityDbMetadata>;\n enums: EnumMetadata;\n pgEnums: PgEnumMetadata;\n joinTables: string[];\n /** Other non-joist tables in the schema. */\n otherTables: string[];\n totalTables: number;\n}\n\n/** Codegen-time metadata about a given domain entity. */\nexport type Entity = {\n name: string;\n /** The _type_ symbol pointing to the entity itself. */\n type: Import;\n /** The symbol pointing to the entity itself. */\n typeSymbol: Import;\n /** The symbol pointing to the entity itself, directly rather than via entities.ts */\n typeForMetadataFile: Import;\n /** The name of the entity's runtime metadata const. */\n metaName: string;\n /** The symbol pointing to the entity's runtime metadata const. */\n metaType: Import;\n /** The symbol pointing to the entity's EntityId type. */\n idType: Import;\n /** The symbol pointing to the entity's Order type. */\n orderType: Import;\n /** The symbol pointing to the entity's config const. */\n configConst: Import;\n optsType: Import;\n // The names of the entity's codegen'd types, i.e. `AuthorId`, that `resolveNameConflicts` rewrites\n // to `Author_Id` when they would collide with another entity/enum name. The `Import`s above\n // (`idType`/`orderType`/`optsType`) are rebuilt to match when that happens.\n /** i.e. `AuthorId` (or `Author_Id` on conflict). */\n idName: string;\n /** i.e. `AuthorFields`. */\n fieldsName: string;\n /** i.e. `AuthorOpts`. */\n optsName: string;\n /** i.e. `AuthorIdsOpts`. */\n idsOptsName: string;\n /** i.e. `AuthorFilter`. */\n filterName: string;\n /** i.e. `AuthorGraphQLFilter`. */\n graphqlFilterName: string;\n /** i.e. `AuthorOrder`. */\n orderName: string;\n /** i.e. `AuthorFactoryExtras`. */\n factoryExtrasName: string;\n /** i.e. `AuthorScope`. */\n scopeName: string;\n /** i.e. `AuthorScopes`. */\n scopesName: string;\n};\n\nexport type DatabaseColumnType =\n | \"boolean\"\n | \"int\"\n | \"uuid\"\n | \"numeric\"\n | \"smallint\"\n | \"integer\"\n | \"bigint\"\n | \"decimal\"\n | \"real\"\n | \"smallserial\"\n | \"serial\"\n | \"bigserial\"\n | \"double precision\"\n | \"text\"\n | \"citext\"\n | \"character varying\"\n | \"varchar\"\n | \"time without time zone\"\n | \"timestamp with time zone\"\n | \"timestamp without time zone\"\n | \"date\"\n | \"jsonb\"\n | \"bytea\"\n | \"tsvector\"\n | \"tstzrange\";\n\n/**\n * A logical entity field.\n *\n * I.e. it may be a physical db column, or multiple physical db columns, or a \"virtual\" field like\n * the one-to-many collection side of a many-to-one foreign key. */\ninterface Field {\n fieldName: string;\n ignore?: boolean;\n}\n\nexport type PrimitiveTypescriptType = \"boolean\" | \"string\" | \"number\" | \"Object\" | \"bigint\" | \"Uint8Array\" | Code;\n\nexport type PrimitiveField = Field & {\n kind: \"primitive\";\n columnName: string;\n /** Physical table owner, unchanged by domain inheritance specialization. */\n columnOwner: Entity;\n columnType: DatabaseColumnType;\n columnDefault: number | boolean | string | null;\n columnGenerated: boolean;\n /** Database nullability, unchanged by domain inheritance specialization. */\n columnNotNull: boolean;\n // The fieldType might be code for jsonb columns or primitive array columns, i.e. string[]\n fieldType: PrimitiveTypescriptType | Import;\n rawFieldType: PrimitiveTypescriptType;\n notNull: boolean;\n derived: \"orm\" | \"sync\" | \"async\" | false;\n protected: boolean;\n unique: boolean;\n superstruct: Import | undefined;\n zodSchema: Import | undefined;\n customSerde: Import | undefined;\n isArray: boolean;\n hasConfigDefault: boolean;\n lazy?: boolean;\n};\n\nexport type EnumField = Field & {\n kind: \"enum\";\n columnName: string;\n /** Physical table owner, unchanged by domain inheritance specialization. */\n columnOwner: Entity;\n columnType: DatabaseColumnType;\n columnDefault: number | boolean | string | null;\n columnGenerated: boolean;\n columnNotNull: boolean;\n derived: \"sync\" | \"async\" | false;\n enumName: string;\n enumType: Import;\n enumDetailType: Import;\n enumDetailsType: Import;\n enumRows: EnumRow[];\n notNull: boolean;\n isArray: boolean;\n hasConfigDefault: boolean;\n};\n\nexport type PgEnumField = Field & {\n kind: \"pg-enum\";\n columnName: string;\n /** Physical table owner, unchanged by domain inheritance specialization. */\n columnOwner: Entity;\n columnDefault: number | boolean | string | null;\n columnGenerated: boolean;\n columnNotNull: boolean;\n /** I.e. `favorite_shape`. */\n dbType: string;\n /** I.e. `FavoriteShape`. */\n enumName: string;\n enumType: Import;\n enumValues: string[];\n notNull: boolean;\n hasConfigDefault: boolean;\n};\n\n/** I.e. a `Book.author` reference pointing to an `Author`. */\nexport type ManyToOneField = Field & {\n kind: \"m2o\";\n columnName: string;\n /** Physical table owner, unchanged by domain inheritance specialization. */\n columnOwner: Entity;\n columnDefault?: number | boolean | string | null;\n columnGenerated: boolean;\n columnNotNull: boolean;\n dbType: string;\n otherFieldName: string;\n otherEntity: Entity;\n notNull: boolean;\n isDeferredAndDeferrable: boolean;\n constraintName: string;\n derived: \"async\" | false;\n hasConfigDefault: boolean;\n onDelete: Action;\n};\n\n/** I.e. a `Author.books` collection. */\nexport type OneToManyField = Field & {\n kind: \"o2m\";\n singularName: string;\n otherEntity: Entity;\n otherFieldName: string;\n otherColumnName: string;\n otherColumnNotNull: boolean;\n isLargeCollection: boolean;\n orderBy: { field: string; direction: \"ASC\" | \"DESC\" } | undefined;\n softDeletes: \"include\" | \"exclude\" | undefined;\n};\n\n/** I.e. a `Author.image` reference when `image.author_id` is unique. */\nexport type OneToOneField = Field & {\n kind: \"o2o\";\n otherEntity: Entity;\n otherFieldName: string;\n otherColumnName: string;\n otherColumnNotNull: boolean;\n};\n\nexport type ManyToManyField = Field & {\n kind: \"m2m\";\n joinTableName: string;\n singularName: string;\n columnName: string;\n otherEntity: Entity;\n otherFieldName: string;\n otherColumnName: string;\n isLargeCollection: boolean;\n isDeferredAndDeferrable: boolean;\n derived: \"async\" | \"otherSide\" | false;\n softDeletes: \"include\" | \"exclude\" | undefined;\n /** Whether the join table has a surrogate `id` PK; if false the FK pair is the composite PK. */\n hasJoinTableId: boolean;\n};\n\n/** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */\nexport type ManyToManyEnumField = Field & {\n kind: \"m2mEnum\";\n joinTableName: string;\n /** The entity's FK column, e.g. `publisher_id`. */\n columnName: string;\n /** The enum's FK column, e.g. `logo_color_id`. */\n otherColumnName: string;\n enumName: string;\n enumType: Import;\n enumDetailType: Import;\n enumDetailsType: Import;\n enumRows: EnumRow[];\n /** Whether the join table has a surrogate `id` PK; if false the FK pair is the composite PK. */\n hasJoinTableId: boolean;\n};\n\n/** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */\nexport type PolymorphicField = Field & {\n kind: \"poly\";\n fieldType: string; // The name of the type union, eg `CommentParent`\n notNull: boolean;\n hasConfigDefault: boolean;\n components: PolymorphicFieldComponent[];\n};\n\n/** A column such as `parent_book_id` or `parent_book_review_id`. */\nexport type PolymorphicFieldComponent = {\n columnName: string;\n /** Physical table owner, unchanged by domain inheritance specialization. */\n columnOwner: Entity;\n otherFieldName: string; // eg `comment` or `comments`\n otherEntity: Entity;\n isDeferredAndDeferrable: boolean;\n constraintName: string;\n notNull: false; // Added to structurally match ManyToOneField\n};\n\nexport type FieldNameOverrides = {\n fieldName?: string;\n otherFieldName?: string;\n};\n\n/** Adapts the generally-great pg-structure metadata into our specific ORM types. */\nexport class EntityDbMetadata {\n entity: Entity;\n primaryKey: PrimitiveField;\n primitives: PrimitiveField[];\n enums: EnumField[];\n pgEnums: PgEnumField[];\n manyToOnes: ManyToOneField[];\n oneToManys: OneToManyField[];\n largeOneToManys: OneToManyField[];\n oneToOnes: OneToOneField[];\n manyToManys: ManyToManyField[];\n largeManyToManys: ManyToManyField[];\n manyToManyEnums: ManyToManyEnumField[];\n polymorphics: PolymorphicField[];\n tableName: string;\n tagName: string;\n createdAt: PrimitiveField | undefined;\n updatedAt: PrimitiveField | undefined;\n deletedAt: PrimitiveField | undefined;\n baseClassName: string | undefined;\n baseType: EntityDbMetadata | undefined;\n subTypes: EntityDbMetadata[] = [];\n inheritanceType: \"sti\" | \"cti\" | undefined;\n /** This will only be set on the base meta. */\n stiDiscriminatorField?: string;\n /** This will only be set on the sub metas. */\n stiDiscriminatorValue?: number;\n abstract: boolean;\n nonDeferredFkOrder: number = -1;\n uniqueConstraints?: string[][];\n /** Gates mutation targets, not reads; false when required columns or array storage have no supported mutation mapping. */\n supportsEmExecute?: boolean;\n /** Original table fields, captured before inheritance partitions or specializes them. */\n physicalMetadata?: EntityDbMetadata;\n\n constructor(config: Config, table: Table, enums: EnumMetadata = {}) {\n this.entity = makeEntity(tableToEntityName(config, table));\n\n if (isSubClassTable(table)) {\n this.baseClassName = tableToEntityName(config, table.columns.get(\"id\").foreignKeys[0].referencedTable);\n this.inheritanceType = \"cti\";\n }\n\n this.primaryKey =\n table.columns\n .filter((c) => c.isPrimaryKey)\n .map((column) => newPrimitive(config, this.entity, column, table))[0] ||\n fail(`No primary key found for ${table.name}`);\n\n this.primitives = table.columns\n .filter((c) => !c.isPrimaryKey && !c.isForeignKey)\n .filter((c) => !isEnumArray(c) && !isPgEnum(c))\n .map((column) => newPrimitive(config, this.entity, column, table))\n .filter((f) => !f.ignore);\n\n this.enums = [\n ...table.m2oRelations\n .filter((r) => isEnumTable(config, r.targetTable))\n .map((r) => newEnumField(config, this.entity, r, enums))\n .filter((f) => !f.ignore),\n ...table.columns\n .filter((c) => isEnumArray(c))\n .map((column) => newEnumArrayField(config, this.entity, column, enums))\n .filter((f) => !f.ignore),\n ];\n this.pgEnums = table.columns\n .filter((c) => isPgEnum(c))\n .map((column) => newPgEnumField(config, this.entity, column))\n .filter((f) => !f.ignore);\n\n this.manyToOnes = table.m2oRelations\n .filter((r) => !isEnumTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => !isComponentOfPolymorphicRelation(config, r))\n .filter((r) => !isBaseClassForeignKey(r))\n .map((r) => newManyToOneField(config, this.entity, r))\n .filter((f) => !f.ignore);\n\n // We split these into regular/large...\n const allOneToManys = table.o2mRelations\n // ManyToMany join tables also show up as OneToMany tables in pg-structure\n .filter((r) => !isJoinTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => !isOneToOneRelation(r))\n .map((r) => newOneToMany(config, this.entity, r))\n // Do not generate o2m for ReactiveReferences\n .filter((f) => !isReactiveReference(config, f.otherEntity, f.otherFieldName))\n .filter((f) => !f.ignore);\n this.oneToManys = allOneToManys.filter((f) => !f.isLargeCollection);\n this.largeOneToManys = allOneToManys.filter((f) => f.isLargeCollection);\n\n this.oneToOnes = table.o2mRelations\n // ManyToMany join tables also show up as OneToMany tables in pg-structure\n .filter((r) => !isJoinTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => !isBaseClassForeignKey(r))\n .filter((r) => isOneToOneRelation(r))\n .map((r) => newOneToOne(config, this.entity, r))\n .filter((f) => !f.ignore);\n\n // We split these into regular/large\n const allManyToManys = table.m2mRelations\n // pg-structure is really loose on what it considers a m2m relationship, i.e. any entity\n // that has a foreign key to us, and a foreign key to something else, is automatically\n // considered as a join table/m2m between \"us\" and \"something else\". Filter these out\n // by looking for only true join tables, i.e. tables with only id, fk1, and fk2.\n .filter((r) => isJoinTable(config, r.joinTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n // Join tables whose \"other\" side is an enum table become EnumCollections instead.\n .filter((r) => !isEnumTable(config, r.targetTable))\n .map((r) => newManyToManyField(config, this.entity, r))\n .filter((f) => !f.ignore);\n this.manyToManys = allManyToManys.filter((f) => !f.isLargeCollection);\n this.largeManyToManys = allManyToManys.filter((f) => f.isLargeCollection);\n\n // A join table between us and an enum table, i.e. `Publisher.logoColors`.\n this.manyToManyEnums = table.m2mRelations\n .filter((r) => isJoinTable(config, r.joinTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => isEnumTable(config, r.targetTable))\n .map((r) => newManyToManyEnumField(config, this.entity, r, enums))\n .filter((f) => !f.ignore);\n\n this.polymorphics = polymorphicRelations(config, table).map((rc) =>\n newPolymorphicField(config, table, this.entity, rc),\n );\n\n this.tableName = table.name;\n this.tagName = config.entities[this.entity.name]?.tag;\n this.abstract = config.entities[this.entity.name]?.abstract || false;\n\n const { createdAtConf, updatedAtConf, deletedAtConf } = getTimestampConfig(config);\n this.createdAt = this.primitives.find((f) => createdAtConf.names.includes(f.columnName));\n this.updatedAt = this.primitives.find((f) => updatedAtConf.names.includes(f.columnName));\n this.deletedAt = this.primitives.find((f) => deletedAtConf.names.includes(f.columnName));\n this.uniqueConstraints = inferUniqueConstraints(this, table);\n const fields = [this.primaryKey, ...this.primitives, ...this.enums, ...this.pgEnums, ...this.manyToOnes];\n const mapped = new Set(fields.map((field) => field.columnName));\n // Composite keys and unmapped NOT NULL columns cannot be supplied through mutation field names.\n this.supportsEmExecute =\n table.primaryKey?.columns.length === 1 &&\n this.primaryKey.columnName === \"id\" &&\n // Native enum and multidimensional arrays still have scalar field mappings.\n table.columns.every((column) => column.arrayDimension <= 1 && !(isArray(column) && isPgEnum(column))) &&\n // JSON/schema serdes encode one JSON value, not a SQL array. Date-mode serdes also encode one scalar.\n // Custom element mappers and Temporal array serdes have separate elementwise write paths.\n !this.primitives.some(\n (field) =>\n field.isArray &&\n !field.customSerde &&\n (field.columnType === \"jsonb\" ||\n (!config.temporal &&\n (field.columnType === \"date\" ||\n field.columnType === \"timestamp with time zone\" ||\n field.columnType === \"timestamp without time zone\"))),\n ) &&\n table.columns.every(\n (column) =>\n mapped.has(column.name) || !column.notNull || column.defaultWithTypeCast !== null || column.isGenerated,\n );\n }\n\n get name(): string {\n return this.entity.name;\n }\n\n get nonDeferredFks(): Array<ManyToOneField | PolymorphicFieldComponent> {\n return [\n ...this.manyToOnes.filter((r) => !r.isDeferredAndDeferrable),\n ...this.polymorphics.flatMap((p) => p.components).filter((c) => !c.isDeferredAndDeferrable),\n ];\n }\n\n get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n }\n}\n\nfunction isMultiColumnForeignKey(r: M2ORelation | O2MRelation | M2MRelation) {\n return r.foreignKey.columns.length > 1;\n}\n\nfunction isBaseClassForeignKey(r: M2ORelation | O2MRelation | M2MRelation) {\n return r.foreignKey.columns.length === 1 && r.foreignKey.columns[0].name === \"id\";\n}\n\nfunction isOneToOneRelation(r: O2MRelation) {\n // otherColumn will be the images.book_id in the other table\n const otherColumn = r.foreignKey.columns[0];\n // r.foreignKey.index is the index on _us_ (i.e. our Book primary key), so look up indexes in the target table\n const indexes = r.targetTable.columns.find((c) => c.name == otherColumn.name)?.uniqueIndexes || [];\n return indexes.find(isOneToOneIndex) !== undefined;\n}\n\n// If the unique index has only one column and is NOT a partial index, it's a one-to-one\nfunction isOneToOneIndex(i: Index) {\n return i.columns.length === 1 && !i.isPartial;\n}\n\n/** Infers field names from unique constraints, i.e. `(author_id, title)` becomes `author, title`. */\nfunction inferUniqueConstraints(meta: EntityDbMetadata, table: Table): string[][] {\n return table.uniqueConstraints.flatMap((constraint) => {\n if (constraint.index.isPartial) return [];\n const fields = Array.from(constraint.columns).map((column) => fieldNameForColumn(meta, column.name));\n if (fields.some((field) => field === undefined)) return [];\n return [fields as string[]];\n });\n}\n\n/** Returns the queryable field name for a unique constraint column. */\nfunction fieldNameForColumn(meta: EntityDbMetadata, columnName: string): string | undefined {\n const primitive = meta.primitives.find((field) => field.columnName === columnName);\n if (primitive && !primitive.derived && !primitive.isArray && !primitive.customSerde) return primitive.fieldName;\n\n const enumField = meta.enums.find((field) => field.columnName === columnName);\n if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;\n\n const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);\n if (pgEnum) return pgEnum.fieldName;\n\n const manyToOne = meta.manyToOnes.find((field) => field.columnName === columnName);\n if (manyToOne && !manyToOne.derived) return manyToOne.fieldName;\n\n return undefined;\n}\n\ntype PolymorphicRelation = { fieldName: string; notNull: boolean };\nfunction polymorphicRelations(config: Config, table: Table): PolymorphicRelation[] {\n const entity = config.entities[tableToEntityName(config, table)];\n return Object.entries(entity?.relations ?? {})\n .filter(([, r]) => r.polymorphic)\n .map(([fieldName, { polymorphic }]) => ({ fieldName, notNull: polymorphic === \"notNull\" }));\n}\n\nfunction polymorphicFieldName(config: Config, r: M2ORelation | O2MRelation) {\n const { name } = r.foreignKey.columns[0];\n const table = r.type === \"m2o\" ? r.sourceTable : r.targetTable;\n return polymorphicRelations(config, table).find((pr) => name.startsWith(`${snakeCase(pr.fieldName)}_`))?.fieldName;\n}\n\nfunction isComponentOfPolymorphicRelation(config: Config, r: M2ORelation) {\n return polymorphicFieldName(config, r) !== undefined;\n}\n\nfunction determineUserType(\n fieldType: PrimitiveTypescriptType,\n superstruct: string | undefined,\n zodSchema: string | undefined,\n userFieldType: string | undefined,\n) {\n if (fieldType === \"Object\" && superstruct) {\n return superstructType(superstruct);\n }\n\n if (fieldType === \"Object\" && zodSchema) {\n return zodSchemaType(zodSchema);\n }\n\n if (userFieldType) {\n return userFieldTypeType(userFieldType);\n }\n\n return fieldType;\n}\n\nfunction newPrimitive(config: Config, entity: Entity, column: Column, table: Table): PrimitiveField {\n const fieldName = primitiveFieldName(column.name);\n const columnName = column.name;\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const array = isArray(column);\n const fieldType = mapType(config, table.name, columnName, columnType);\n const customSerde = serdeConfig(config, entity, fieldName);\n const superstruct = superstructConfig(config, entity, fieldName);\n const zodSchema = zodSchemaConfig(config, entity, fieldName);\n const userFieldType = fieldTypeConfig(config, entity, fieldName);\n const maybeUserType = determineUserType(fieldType, superstruct, zodSchema, userFieldType);\n const unique = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"primitive\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnType,\n fieldType: array ? code`${maybeUserType}[]` : maybeUserType,\n rawFieldType: fieldType,\n notNull: column.notNull,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: fieldDerived(config, entity, fieldName),\n protected: isProtected(config, entity, fieldName),\n unique,\n ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),\n superstruct: fieldType === \"Object\" && superstruct ? Import.from(superstruct) : undefined,\n zodSchema: fieldType === \"Object\" && zodSchema ? Import.from(zodSchema) : undefined,\n customSerde: customSerde ? serdeType(customSerde) : undefined,\n isArray: array,\n hasConfigDefault, // can be set to true by scanEntityFiles\n lazy: isLazyField(config, entity, fieldName),\n };\n}\n\nfunction fieldDerived(config: Config, entity: Entity, fieldName: string): PrimitiveField[\"derived\"] {\n if (ormMaintainedFields.includes(fieldName)) {\n return \"orm\";\n } else if (isGetterField(config, entity, fieldName)) {\n return \"sync\";\n } else if (isReactiveField(config, entity, fieldName)) {\n return \"async\";\n } else {\n return false;\n }\n}\n\nfunction fkFieldDerived(config: Config, entity: Entity, fieldName: string): ManyToOneField[\"derived\"] {\n if (isReactiveReference(config, entity, fieldName)) {\n return \"async\";\n } else {\n return false;\n }\n}\n\nfunction newEnumField(config: Config, entity: Entity, r: M2ORelation, enums: EnumMetadata): EnumField {\n const column = r.foreignKey.columns[0];\n const columnName = column.name;\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const fieldName = enumFieldName(column.name);\n const enumName = tableToEntityName(config, r.targetTable);\n const enumType = imp(`${enumName}@./entities.ts`);\n const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);\n const enumDetailsType = imp(`${enumName}Details@./entities.ts`);\n const notNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"enum\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnType,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: fieldDerived(config, entity, fieldName) as EnumField[\"derived\"],\n enumName,\n enumType,\n enumDetailType,\n enumDetailsType,\n notNull,\n ignore,\n enumRows: enums[r.targetTable.name].rows,\n isArray: false,\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newEnumArrayField(config: Config, entity: Entity, column: Column, enums: EnumMetadata): EnumField {\n const columnName = column.name;\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const fieldName = enumFieldName(column.name);\n // Find the enum table name via the comment hint (instead of a FK constraint), and strip the enum= prefix\n const enumTable = column.comment!.replace(\"enum=\", \"\");\n const enumName = (enums[enumTable] || fail(`Could not find enum ${enumTable}`)).name;\n const enumType = imp(`${enumName}@./entities.ts`);\n const enumDetailType = imp(`${plural(enumName)}@./entities.ts`);\n const enumDetailsType = imp(`${enumName}Details@./entities.ts`);\n const notNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"enum\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnType,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: fieldDerived(config, entity, fieldName) as EnumField[\"derived\"],\n enumName,\n enumType,\n enumDetailType,\n enumDetailsType,\n notNull,\n ignore,\n enumRows: enums[enumTable].rows,\n isArray: true,\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newPgEnumField(config: Config, entity: Entity, column: Column): PgEnumField {\n const fieldName = primitiveFieldName(column.name);\n const columnName = column.name;\n const enumName = pascalCase(column.type.name);\n const enumType = imp(`${enumName}@./entities.ts`);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"pg-enum\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n dbType: column.type.name,\n enumType,\n enumName,\n enumValues: (column.type as EnumType).values,\n notNull: column.notNull,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n ignore: isFieldIgnored(config, entity, fieldName, column.notNull, column.default !== null),\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newManyToOneField(config: Config, entity: Entity, r: M2ORelation): ManyToOneField {\n const column = r.foreignKey.columns[0];\n const columnName = column.name;\n const dbType = r.foreignKey.columns[0].type.shortName!;\n const fieldName = referenceName(config, entity, r);\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const isOneToOne = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;\n const otherFieldName = isOneToOne\n ? oneToOneName(config, otherEntity, entity, r)\n : collectionName(config, otherEntity, entity, r).fieldName;\n const notNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName, notNull, column.default !== null);\n const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;\n const derived = fkFieldDerived(config, entity, fieldName);\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"m2o\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName,\n columnName,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n otherEntity,\n otherFieldName,\n notNull,\n ignore,\n derived,\n dbType,\n isDeferredAndDeferrable,\n constraintName: r.foreignKey.name,\n hasConfigDefault, // can be set to true by scanEntityFiles\n onDelete: r.foreignKey.onDelete,\n };\n}\n\nfunction newOneToMany(config: Config, entity: Entity, r: O2MRelation): OneToManyField {\n const column = r.foreignKey.columns[0];\n // source == parent i.e. the reference of the foreign key column\n // target == child i.e. the table with the foreign key column in it\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const { singularName, fieldName } = collectionName(config, entity, otherEntity, r);\n const otherFieldName = referenceName(config, otherEntity, r);\n const orderBy =\n config.entities[entity.name]?.relations?.[fieldName]?.orderBy ?? config.entities[otherEntity.name]?.orderBy;\n return {\n kind: \"o2m\",\n fieldName,\n singularName,\n otherEntity,\n otherFieldName,\n otherColumnName: column.name,\n otherColumnNotNull: column.notNull,\n ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),\n isLargeCollection: isLargeCollection(config, entity, fieldName),\n orderBy: parseOrder(orderBy),\n softDeletes: softDeletesConfig(config, entity, fieldName),\n };\n}\n\nfunction newOneToOne(config: Config, entity: Entity, r: O2MRelation): OneToOneField {\n const column = r.foreignKey.columns[0];\n // source == parent i.e. the reference of the foreign key column\n // target == child i.e. the table with the foreign key column in it\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const fieldName = oneToOneName(config, entity, otherEntity, r);\n const otherFieldName = referenceName(config, otherEntity, r);\n const otherColumnName = column.name;\n const otherColumnNotNull = column.notNull;\n const ignore = isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName);\n return { kind: \"o2o\", fieldName, otherEntity, otherFieldName, otherColumnName, otherColumnNotNull, ignore };\n}\n\nfunction newManyToManyField(config: Config, entity: Entity, r: M2MRelation): ManyToManyField {\n const { foreignKey, targetForeignKey, targetTable } = r;\n const otherEntity = makeEntity(tableToEntityName(config, targetTable));\n // For foo_to_bar.some_foo_id use the `some_foo_id` column i.e. `someFoos`\n const fieldName = manyToManyName(targetForeignKey.columns[0]);\n const otherFieldName = manyToManyName(foreignKey.columns[0]);\n const isDeferredAndDeferrable = targetForeignKey.isDeferred && targetForeignKey.isDeferrable;\n\n // Determine if this m2m is derived:\n // - \"async\" if this side is explicitly marked as a ReactiveManyToMany\n // - \"otherSide\" if the OTHER side is marked as a ReactiveManyToMany (making this the read-only other side)\n // - false otherwise (regular m2m)\n const isThisSideDerived = isReactiveManyToMany(config, entity, fieldName);\n const isOtherSideDerived = isReactiveManyToMany(config, otherEntity, otherFieldName);\n const derived = isThisSideDerived ? \"async\" : isOtherSideDerived ? \"otherSide\" : false;\n\n return {\n kind: \"m2m\",\n joinTableName: r.joinTable.name,\n fieldName,\n singularName: singular(fieldName),\n columnName: foreignKey.columns[0].name,\n otherEntity,\n otherFieldName,\n otherColumnName: targetForeignKey.columns[0].name,\n ignore: isFieldIgnored(config, entity, fieldName) || isFieldIgnored(config, otherEntity, otherFieldName),\n isLargeCollection: isLargeCollection(config, entity, fieldName),\n isDeferredAndDeferrable,\n derived,\n softDeletes: softDeletesConfig(config, entity, fieldName),\n hasJoinTableId: joinTableHasId(r.joinTable),\n };\n}\n\nfunction newManyToManyEnumField(\n config: Config,\n entity: Entity,\n r: M2MRelation,\n enums: EnumMetadata,\n): ManyToManyEnumField {\n const { foreignKey, targetForeignKey, targetTable } = r;\n // For publisher_logo_colors.logo_color_id use the `logo_color_id` column i.e. `logoColors`\n const fieldName = manyToManyName(targetForeignKey.columns[0]);\n const enumName = tableToEntityName(config, targetTable);\n return {\n kind: \"m2mEnum\",\n joinTableName: r.joinTable.name,\n fieldName,\n columnName: foreignKey.columns[0].name,\n otherColumnName: targetForeignKey.columns[0].name,\n enumName,\n enumType: imp(`${enumName}@./entities.ts`),\n enumDetailType: imp(`${plural(enumName)}@./entities.ts`),\n enumDetailsType: imp(`${enumName}Details@./entities.ts`),\n enumRows: enums[targetTable.name].rows,\n ignore: isFieldIgnored(config, entity, fieldName),\n hasJoinTableId: joinTableHasId(r.joinTable),\n };\n}\n\nfunction newPolymorphicField(config: Config, table: Table, entity: Entity, pr: PolymorphicRelation) {\n const { fieldName, notNull } = pr;\n const components = table.m2oRelations\n .filter((r) => !isEnumTable(config, r.targetTable))\n .filter((r) => !isMultiColumnForeignKey(r))\n .filter((r) => polymorphicFieldName(config, r) === fieldName)\n .map((r) => newPolymorphicFieldComponent(config, entity, r));\n const fieldType = `${entity.name}${pascalCase(fieldName)}`;\n const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);\n return {\n kind: \"poly\" as const,\n fieldName,\n fieldType,\n notNull,\n components,\n hasConfigDefault, // can be set to true by scanEntityFiles\n };\n}\n\nfunction newPolymorphicFieldComponent(config: Config, entity: Entity, r: M2ORelation): PolymorphicFieldComponent {\n const column = r.foreignKey.columns[0];\n const columnName = column.name;\n const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));\n const isOneToOne = column.uniqueIndexes.find(isOneToOneIndex) !== undefined;\n const otherFieldName = isOneToOne\n ? oneToOneName(config, otherEntity, entity, r)\n : collectionName(config, otherEntity, entity, r).fieldName;\n const isDeferredAndDeferrable = r.foreignKey.isDeferred && r.foreignKey.isDeferrable;\n return {\n columnName,\n columnOwner: entity,\n otherEntity,\n otherFieldName,\n isDeferredAndDeferrable,\n constraintName: r.foreignKey.name,\n notNull: false,\n };\n}\n\nfunction isFieldNameOverrides(maybeOverride: JSONData | undefined): maybeOverride is FieldNameOverrides {\n return (\n maybeOverride !== null &&\n !Array.isArray(maybeOverride) &&\n typeof maybeOverride === \"object\" &&\n Object.keys(maybeOverride).some((k) => k === \"fieldName\" || k === \"otherFieldName\")\n );\n}\n\n/** Finds the field name for o2o side of a o2o/m2o. */\nexport function oneToOneName(\n config: Config,\n // I.e. the Book for o2o Book.image <-- `images.book_id`\n refEntity: Entity,\n // I.e. the Image for o2o Book.image <-- `images.book_id`\n keyEntity: Entity,\n r: M2ORelation | O2MRelation,\n): string {\n // If the name is overridden then use that\n const overrides = r.foreignKey.columns[0].commentData;\n if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {\n return overrides.otherFieldName;\n }\n // For `comments.parent_book_review_id`, we would just use `BookReview.comment` as the name\n // For `authors.draft_current_book_id`, we would just use `Book.author` as the name\n // For `project_items.current_selection_id`, we would use `HomeownerSelection.currentProjectItem`\n const refTable = r instanceof M2ORelation ? r.targetTable : r.sourceTable;\n // Does the ref table have any m2o pointing table at the key table?\n const found = refTable.m2oRelations.find((s) => tableToEntityName(config, s.targetTable) === keyEntity.name);\n // console.log({refTable: refTable.name, keyTable: keyTable.name, found: found?.name, fieldName});\n if (!found) {\n // If there aren't any m2os, just use the raw type name like `.image` or `.comment`\n return camelCase(keyEntity.name);\n } else {\n // If there is a m2o, assume we might conflict, and use the column name to at least be unique\n // Start with `book` from `images.book_id` or `current_draft_book` from `authors.current_draft_book_id`\n let fieldName = r.foreignKey.columns[0].name.replace(idSuffix, \"\");\n // Suffix the new type that we're pointing to, to `current_draft_book_author`\n fieldName = `${fieldName}_${keyEntity.name}`;\n // And drop the `book`, to `current_draft__author`\n fieldName = fieldName.replace(refEntity.name.toLowerCase(), \"\");\n // Then camel case, to `currentDraftAuthor`\n return camelCase(fieldName);\n }\n}\n\nconst idSuffix = /_id$|Id$/;\n\nexport function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string {\n const [column] = r.foreignKey.columns;\n const overrides = column.commentData;\n return (\n polymorphicFieldName(config, r) ??\n // If the name is overridden then use that\n (isFieldNameOverrides(overrides) ? overrides.fieldName : undefined) ??\n camelCase(column.name.replace(idSuffix, \"\"))\n );\n}\n\nfunction enumFieldName(columnName: string) {\n return camelCase(columnName.replace(idSuffix, \"\"));\n}\n\nfunction primitiveFieldName(columnName: string) {\n return camelCase(columnName);\n}\n\nexport function manyToManyName(column: Column) {\n const overrides = column.commentData;\n // If the name is overridden then use that\n if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {\n return overrides.otherFieldName;\n }\n return camelCase(plural(column.name.replace(idSuffix, \"\")));\n}\n\n/** Returns the collection name to use on `entity` when referring to `otherEntity`s. */\nexport function collectionName(\n config: Config,\n // I.e. the Author for o2m Author.books --> books.author_id\n singleEntity: Entity,\n // I.e. the Book for o2m Author.books --> books.author_id\n collectionEntity: Entity,\n r: M2ORelation | O2MRelation | M2MRelation,\n): { fieldName: string; singularName: string } {\n const [column] = r.foreignKey.columns;\n const overrides = column.commentData;\n // If the name is overridden then use that, but also singularize it\n if (isFieldNameOverrides(overrides) && overrides.otherFieldName) {\n const fieldName = overrides.otherFieldName;\n return { fieldName, singularName: singular(fieldName) };\n }\n // I.e. if the m2o is `books.author_id`, use `Author.books` as the collection name (we pluralize at the end).\n let singularName = collectionEntity.name;\n // Check if we have multiple FKs from collectionEntity --> singleEntity and prefix with FK name if so\n const sourceTable = r.type === \"m2o\" ? r.sourceTable : r.targetTable;\n const targetTable = r.type === \"m2o\" ? r.targetTable : r.sourceTable;\n // If `books.foo_author_id` and `books.bar_author_id` both exist\n if (r.type !== \"m2m\" && sourceTable.m2oRelations.filter((r) => r.targetTable === targetTable).length > 1) {\n // Use `fooAuthorBooks`, `barAuthorBooks`\n singularName = `${column.name.replace(idSuffix, \"\")}_${singularName}`;\n }\n // If we've guessed `Book.bookReviews` based on `book_reviews.book_id` --> `bookReviews`, strip the `Book` prefix\n if (singularName.length > singleEntity.name.length && singularName.startsWith(singleEntity.name)) {\n singularName = singularName.substring(singleEntity.name.length);\n }\n // camelize the name\n singularName = camelCase(singularName);\n // and pluralize for fieldName\n return { fieldName: plural(singularName), singularName };\n}\n\nexport function failIfOverlappingFieldNames(entity: EntityDbMetadata): void {\n const allFields = [\n entity.primaryKey,\n ...entity.primitives,\n ...entity.enums,\n ...entity.pgEnums,\n ...entity.manyToOnes,\n ...entity.oneToManys,\n ...entity.largeOneToManys,\n ...entity.oneToOnes,\n ...entity.manyToManys,\n ...entity.largeManyToManys,\n ...entity.manyToManyEnums,\n ...entity.polymorphics,\n ];\n Object.entries(groupBy(allFields, (f) => f.fieldName)).forEach(([fieldName, fields]) => {\n if (fields.length > 1) {\n throw new Error(\n `In ${entity.name}, found multiple fields named '${fieldName}': ${fields.map((f) => f.kind).join(\" \")}`,\n );\n }\n });\n}\n\nexport function makeEntity(entityName: string): Entity {\n // Default to the conventional names; `resolveNameConflicts` rewrites them if they collide.\n const names = entitySymbolNames(entityName);\n return {\n name: entityName,\n type: entityType(entityName),\n typeSymbol: entityTypeSymbol(entityName),\n typeForMetadataFile: entityTypeForMetadataFile(entityName),\n metaName: metaName(entityName),\n metaType: metaType(entityName),\n idType: entityTypeImport(entityName, names.idName),\n orderType: entityTypeImport(entityName, names.orderName),\n optsType: entityTypeImport(entityName, names.optsName),\n configConst: imp(`${camelCase(entityName)}Config@./entities.ts`, {\n definedIn: `./codegen/${entityName}Codegen.ts`,\n }),\n ...names,\n };\n}\n\n/**\n * Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.\n *\n * `makeEntity` mints a fresh `Entity` for every relation's `otherEntity`, so each entity ends up with\n * many duplicate objects floating around. Pointing them all at the single `entitiesByName[name].entity`\n * instance means later passes (i.e. `resolveNameConflicts`) only have to update one object per name.\n *\n * Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.\n */\nexport function canonicalizeOtherEntities(db: DbMetadata): void {\n const canonical = (other: Entity) => db.entitiesByName[other.name]?.entity ?? other;\n for (const meta of db.entities) {\n for (const field of [\n ...meta.manyToOnes,\n ...meta.oneToManys,\n ...meta.largeOneToManys,\n ...meta.oneToOnes,\n ...meta.manyToManys,\n ...meta.largeManyToManys,\n ]) {\n field.otherEntity = canonical(field.otherEntity);\n }\n for (const poly of meta.polymorphics) {\n for (const comp of poly.components) comp.otherEntity = canonical(comp.otherEntity);\n }\n if (meta.physicalMetadata) {\n canonicalizeOtherEntities({ ...db, entities: [meta.physicalMetadata] });\n }\n }\n}\n\n/**\n * Rewrites codegen'd type names that collide with another exported type name.\n *\n * `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or\n * enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name\n * would collide with it, so we fall back to `Author_Scope` / `Author_Order`.\n *\n * Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates\n * the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).\n */\nexport function resolveNameConflicts(config: Config, db: DbMetadata): void {\n // The names exported into `entities.ts` that a codegen'd type could shadow.\n const reserved = new Set<string>(db.entities.map((meta) => meta.name));\n for (const enumData of Object.values(db.enums)) {\n // An enum table exports its (singularized) type, its `Details` type/const, and its pluralized const,\n // i.e. `ChangeRequestAssetScope`, `ChangeRequestAssetScopeDetails`, and `ChangeRequestAssetScopes`.\n const enumName = tableToEntityName(config, enumData.table);\n reserved.add(enumName).add(`${enumName}Details`).add(plural(enumName));\n }\n for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);\n for (const meta of db.entities) {\n if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);\n }\n}\n\n/** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */\nfunction entitySymbolNames(name: string, reserved?: Set<string>) {\n const pick = (suffix: string) => (reserved?.has(`${name}${suffix}`) ? `${name}_${suffix}` : `${name}${suffix}`);\n return {\n idName: pick(\"Id\"),\n fieldsName: pick(\"Fields\"),\n optsName: pick(\"Opts\"),\n idsOptsName: pick(\"IdsOpts\"),\n filterName: pick(\"Filter\"),\n graphqlFilterName: pick(\"GraphQLFilter\"),\n orderName: pick(\"Order\"),\n factoryExtrasName: pick(\"FactoryExtras\"),\n scopeName: pick(\"Scope\"),\n scopesName: pick(\"Scopes\"),\n };\n}\n\n/** Returns true if any of the entity's conventional type names is already taken. */\nfunction hasNameConflict(name: string, reserved: Set<string>): boolean {\n return Object.values(entitySymbolNames(name)).some((conventional) => reserved.has(conventional));\n}\n\n/** Rewrites an entity's type names (and the `Import`s built from them) to their de-conflicted form. */\nfunction applyEntityNames(entity: Entity, reserved: Set<string>): void {\n const names = entitySymbolNames(entity.name, reserved);\n Object.assign(entity, names);\n entity.idType = entityTypeImport(entity.name, names.idName);\n entity.orderType = entityTypeImport(entity.name, names.orderName);\n entity.optsType = entityTypeImport(entity.name, names.optsName);\n}\n\nfunction entityTypeImport(entityName: string, symbolName: string): Import {\n return imp(`t:${symbolName}@./entities.ts`, { definedIn: `./codegen/${entityName}Codegen.ts` });\n}\n\nfunction metaName(entityName: string): string {\n return `${camelCase(entityName)}Meta`;\n}\n\nfunction metaType(entityName: string): Import {\n return imp(`${metaName(entityName)}@./entities.ts`);\n}\n\nfunction entityType(entityName: string): Import {\n return imp(`t:${entityName}@./entities.ts`);\n}\n\nfunction entityTypeSymbol(entityName: string): Import {\n return imp(`${entityName}@./entities.ts`);\n}\n\nfunction entityTypeForMetadataFile(entityName: string): Import {\n return imp(`${entityName}@./${entityName}.ts`);\n}\n\nfunction mapType(\n config: Config,\n tableName: string,\n columnName: string,\n dbColumnType: DatabaseColumnType,\n): PrimitiveTypescriptType {\n return mapSimpleDbTypeToTypescriptType(config, dbColumnType);\n}\n\nfunction isEnumArray(c: Column): boolean {\n return c.arrayDimension === 1 && !!c.comment && c.comment.startsWith(\"enum=\");\n}\n\nfunction isArray(c: Column): boolean {\n return c.arrayDimension === 1;\n}\n\nfunction isPgEnum(c: Column): boolean {\n return c.type instanceof EnumType;\n}\n\nfunction superstructType(s: string): Import {\n // Assume it's `foo@...`, turn it into `Foo@...`\n const [symbol, ...path] = s.split(\"@\");\n return Import.from(`${pascalCase(symbol)}@${path.join(\"@\")}`);\n}\n\nfunction zodSchemaType(s: string): Code {\n const schema = Import.from(s);\n return code`${Zod}.input<typeof ${schema}>`;\n}\n\nfunction userFieldTypeType(s: string): Import {\n return Import.from(`t:${s}`);\n}\n\nfunction serdeType(s: string): Import {\n return Import.from(s);\n}\n"],"mappings":";;;;;;;;;;;;;AAgDA,MAAM,EAAE,QAAQ,aAAa,UAAA;;AAwQ7B,IAAa,mBAAb,MAA8B;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,WAA+B,CAAC;CAChC;;CAEA;;CAEA;CACA;CACA,qBAA6B;CAC7B;;CAEA;;CAEA;CAEA,YAAY,QAAgB,OAAc,QAAsB,CAAC,GAAG;EAClE,KAAK,SAAS,WAAWA,cAAAA,kBAAkB,QAAQ,KAAK,CAAC;EAEzD,IAAIC,cAAAA,gBAAgB,KAAK,GAAG;GAC1B,KAAK,gBAAgBD,cAAAA,kBAAkB,QAAQ,MAAM,QAAQ,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC,eAAe;GACrG,KAAK,kBAAkB;EACzB;EAEA,KAAK,aACH,MAAM,QACH,QAAQ,MAAM,EAAE,YAAY,CAAC,CAC7B,KAAK,WAAW,aAAa,QAAQ,KAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,MACrEE,cAAAA,KAAK,4BAA4B,MAAM,MAAM;EAE/C,KAAK,aAAa,MAAM,QACrB,QAAQ,MAAM,CAAC,EAAE,gBAAgB,CAAC,EAAE,YAAY,CAAC,CACjD,QAAQ,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAC9C,KAAK,WAAW,aAAa,QAAQ,KAAK,QAAQ,QAAQ,KAAK,CAAC,CAAC,CACjE,QAAQ,MAAM,CAAC,EAAE,MAAM;EAE1B,KAAK,QAAQ,CACX,GAAG,MAAM,aACN,QAAQ,MAAMC,cAAAA,YAAY,QAAQ,EAAE,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,6 +70,8 @@ type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "big
70
70
  type PrimitiveField = Field & {
71
71
  kind: "primitive";
72
72
  columnName: string;
73
+ /** Physical table owner, unchanged by domain inheritance specialization. */
74
+ columnOwner: Entity;
73
75
  columnType: DatabaseColumnType;
74
76
  columnDefault: number | boolean | string | null;
75
77
  columnGenerated: boolean;
@@ -91,6 +93,8 @@ type PrimitiveField = Field & {
91
93
  type EnumField = Field & {
92
94
  kind: "enum";
93
95
  columnName: string;
96
+ /** Physical table owner, unchanged by domain inheritance specialization. */
97
+ columnOwner: Entity;
94
98
  columnType: DatabaseColumnType;
95
99
  columnDefault: number | boolean | string | null;
96
100
  columnGenerated: boolean;
@@ -108,6 +112,8 @@ type EnumField = Field & {
108
112
  type PgEnumField = Field & {
109
113
  kind: "pg-enum";
110
114
  columnName: string;
115
+ /** Physical table owner, unchanged by domain inheritance specialization. */
116
+ columnOwner: Entity;
111
117
  columnDefault: number | boolean | string | null;
112
118
  columnGenerated: boolean;
113
119
  columnNotNull: boolean;
@@ -124,6 +130,8 @@ type PgEnumField = Field & {
124
130
  type ManyToOneField = Field & {
125
131
  kind: "m2o";
126
132
  columnName: string;
133
+ /** Physical table owner, unchanged by domain inheritance specialization. */
134
+ columnOwner: Entity;
127
135
  columnDefault?: number | boolean | string | null;
128
136
  columnGenerated: boolean;
129
137
  columnNotNull: boolean;
@@ -199,8 +207,11 @@ type PolymorphicField = Field & {
199
207
  hasConfigDefault: boolean;
200
208
  components: PolymorphicFieldComponent[];
201
209
  };
210
+ /** A column such as `parent_book_id` or `parent_book_review_id`. */
202
211
  type PolymorphicFieldComponent = {
203
212
  columnName: string;
213
+ /** Physical table owner, unchanged by domain inheritance specialization. */
214
+ columnOwner: Entity;
204
215
  otherFieldName: string;
205
216
  otherEntity: Entity;
206
217
  isDeferredAndDeferrable: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"EntityDbMetadata.d.cts","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;EACA,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;EACA,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;KAGU,cAAc;EACxB;EACA;EACA;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;KAIU,iBAAiB;EAC3B;EACA;EACA;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;;EAEA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;;EAEV;;;KAIU,mBAAmB;EAC7B;EACA;EACA;EACA;EACA,YAAY;;KAGF;EACV;EACA;EACA,aAAa;EACb;EACA;EACA;;KAGU;EACV;EAC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;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;;EAEA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;;EAEV;;;KAIU,mBAAmB;EAC7B;EACA;EACA;EACA;EACA,YAAY;;;KAIF;EACV;;EAEA,aAAa;EACb;EACA,aAAa;EACb;EACA;EACA;;KAGU;EACV;EACA;;;cAIW;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,YAAY,QAAQ,QAAQ,OAAO,OAAO,QAAO;MA+H7C;MAIA,kBAAkB,MAAM,iBAAiB;MAOzC,4BAA4B,MAAM;;;iBAyaxB,aACd,QAAQ,QAER,WAAW,QAEX,WAAW,QACX,GAAG,cAAc;iBAgCH,cAAc,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,cAAc;iBAmB/D,eAAe,QAAQ;;iBAUvB,eACd,QAAQ,QAER,cAAc,QAEd,kBAAkB,QAClB,GAAG,cAAc,cAAc;EAC5B;EAAmB;;iBA4BR,4BAA4B,QAAQ;iBAwBpC,WAAW,qBAAqB;;;;;;;;;;iBA6BhC,0BAA0B,IAAI;;;;;;;;;;;iBAgC9B,qBAAqB,QAAQ,QAAQ,IAAI"}
@@ -70,6 +70,8 @@ type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "big
70
70
  type PrimitiveField = Field & {
71
71
  kind: "primitive";
72
72
  columnName: string;
73
+ /** Physical table owner, unchanged by domain inheritance specialization. */
74
+ columnOwner: Entity;
73
75
  columnType: DatabaseColumnType;
74
76
  columnDefault: number | boolean | string | null;
75
77
  columnGenerated: boolean;
@@ -91,6 +93,8 @@ type PrimitiveField = Field & {
91
93
  type EnumField = Field & {
92
94
  kind: "enum";
93
95
  columnName: string;
96
+ /** Physical table owner, unchanged by domain inheritance specialization. */
97
+ columnOwner: Entity;
94
98
  columnType: DatabaseColumnType;
95
99
  columnDefault: number | boolean | string | null;
96
100
  columnGenerated: boolean;
@@ -108,6 +112,8 @@ type EnumField = Field & {
108
112
  type PgEnumField = Field & {
109
113
  kind: "pg-enum";
110
114
  columnName: string;
115
+ /** Physical table owner, unchanged by domain inheritance specialization. */
116
+ columnOwner: Entity;
111
117
  columnDefault: number | boolean | string | null;
112
118
  columnGenerated: boolean;
113
119
  columnNotNull: boolean;
@@ -124,6 +130,8 @@ type PgEnumField = Field & {
124
130
  type ManyToOneField = Field & {
125
131
  kind: "m2o";
126
132
  columnName: string;
133
+ /** Physical table owner, unchanged by domain inheritance specialization. */
134
+ columnOwner: Entity;
127
135
  columnDefault?: number | boolean | string | null;
128
136
  columnGenerated: boolean;
129
137
  columnNotNull: boolean;
@@ -199,8 +207,11 @@ type PolymorphicField = Field & {
199
207
  hasConfigDefault: boolean;
200
208
  components: PolymorphicFieldComponent[];
201
209
  };
210
+ /** A column such as `parent_book_id` or `parent_book_review_id`. */
202
211
  type PolymorphicFieldComponent = {
203
212
  columnName: string;
213
+ /** Physical table owner, unchanged by domain inheritance specialization. */
214
+ columnOwner: Entity;
204
215
  otherFieldName: string;
205
216
  otherEntity: Entity;
206
217
  isDeferredAndDeferrable: boolean;
@@ -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;EACA,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;EACA,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;KAGU,cAAc;EACxB;EACA;EACA;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;KAIU,iBAAiB;EAC3B;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,UAAU;;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ources":["../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;;EAEA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;;EAEV;;;KAIU,mBAAmB;EAC7B;EACA;EACA;EACA;EACA,YAAY;;;KAIF;EACV;;EAEA,aAAa;EACb;EACA,aAAa;EACb;EACA;EACA;;KAGU;EACV;EACA;;;cAIW;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,YAAY,QAAQ,QAAQ,OAAO,OAAO,QAAO;MA+H7C;MAIA,kBAAkB,MAAM,iBAAiB;MAOzC,4BAA4B,MAAM;;;iBAyaxB,aACd,QAAQ,QAER,WAAW,QAEX,WAAW,QACX,GAAG,cAAc;iBAgCH,cAAc,QAAQ,QAAQ,QAAQ,QAAQ,GAAG,cAAc;iBAmB/D,eAAe,QAAQ;;iBAUvB,eACd,QAAQ,QAER,cAAc,QAEd,kBAAkB,QAClB,GAAG,cAAc,cAAc;EAC5B;EAAmB;;iBA4BR,4BAA4B,QAAQ;iBAwBpC,WAAW,qBAAqB;;;;;;;;;;iBA6BhC,0BAA0B,IAAI;;;;;;;;;;;iBAgC9B,qBAAqB,QAAQ,QAAQ,IAAI"}
@@ -159,6 +159,7 @@ function newPrimitive(config, entity, column, table) {
159
159
  const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
160
160
  return {
161
161
  kind: "primitive",
162
+ columnOwner: entity,
162
163
  columnNotNull: column.notNull,
163
164
  fieldName,
164
165
  columnName,
@@ -204,6 +205,7 @@ function newEnumField(config, entity, r, enums) {
204
205
  const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
205
206
  return {
206
207
  kind: "enum",
208
+ columnOwner: entity,
207
209
  columnNotNull: column.notNull,
208
210
  fieldName,
209
211
  columnName,
@@ -236,6 +238,7 @@ function newEnumArrayField(config, entity, column, enums) {
236
238
  const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
237
239
  return {
238
240
  kind: "enum",
241
+ columnOwner: entity,
239
242
  columnNotNull: column.notNull,
240
243
  fieldName,
241
244
  columnName,
@@ -262,6 +265,7 @@ function newPgEnumField(config, entity, column) {
262
265
  const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
263
266
  return {
264
267
  kind: "pg-enum",
268
+ columnOwner: entity,
265
269
  columnNotNull: column.notNull,
266
270
  fieldName,
267
271
  columnName,
@@ -290,6 +294,7 @@ function newManyToOneField(config, entity, r) {
290
294
  const hasConfigDefault = isFieldHasDefault(config, entity, fieldName);
291
295
  return {
292
296
  kind: "m2o",
297
+ columnOwner: entity,
293
298
  columnNotNull: column.notNull,
294
299
  fieldName,
295
300
  columnName,
@@ -405,6 +410,7 @@ function newPolymorphicFieldComponent(config, entity, r) {
405
410
  const otherEntity = makeEntity(tableToEntityName(config, r.targetTable));
406
411
  return {
407
412
  columnName,
413
+ columnOwner: entity,
408
414
  otherEntity,
409
415
  otherFieldName: column.uniqueIndexes.find(isOneToOneIndex) !== void 0 ? oneToOneName(config, otherEntity, entity, r) : collectionName(config, otherEntity, entity, r).fieldName,
410
416
  isDeferredAndDeferrable: r.foreignKey.isDeferred && r.foreignKey.isDeferrable,