joist-codegen 2.4.0-next.5 → 2.4.0-next.51
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.
- package/build/EntityDbMetadata.cjs +21 -3
- package/build/EntityDbMetadata.cjs.map +1 -1
- package/build/EntityDbMetadata.d.cts +28 -25
- package/build/EntityDbMetadata.d.cts.map +1 -1
- package/build/EntityDbMetadata.d.mts +28 -25
- package/build/EntityDbMetadata.d.mts.map +1 -1
- package/build/EntityDbMetadata.js +21 -3
- package/build/EntityDbMetadata.js.map +1 -1
- package/build/assignTags.d.cts +1 -2
- package/build/assignTags.d.cts.map +1 -1
- package/build/assignTags.d.mts +1 -2
- package/build/assignTags.d.mts.map +1 -1
- package/build/codemods/Codemod.d.cts +1 -2
- package/build/codemods/Codemod.d.cts.map +1 -1
- package/build/codemods/Codemod.d.mts +1 -2
- package/build/codemods/Codemod.d.mts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.cts +1 -2
- package/build/codemods/JscodeshiftMod.d.cts.map +1 -1
- package/build/codemods/JscodeshiftMod.d.mts +1 -2
- package/build/codemods/JscodeshiftMod.d.mts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts +2 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.cts.map +1 -1
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts +2 -2
- package/build/codemods/codemod_0001-rename_has_async_property.d.mts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts +2 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.d.cts.map +1 -1
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts +2 -2
- package/build/codemods/codemod_0002-rename_async_query_fields.d.mts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts +2 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.cts.map +1 -1
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts +2 -2
- package/build/codemods/codemod_0003-rename_find_paginated.d.mts.map +1 -1
- package/build/codemods/index.d.cts +3 -4
- package/build/codemods/index.d.cts.map +1 -1
- package/build/codemods/index.d.mts +3 -4
- package/build/codemods/index.d.mts.map +1 -1
- package/build/config.cjs +8 -3
- package/build/config.cjs.map +1 -1
- package/build/config.d.cts +30 -27
- package/build/config.d.cts.map +1 -1
- package/build/config.d.mts +30 -27
- package/build/config.d.mts.map +1 -1
- package/build/config.js +8 -3
- package/build/config.js.map +1 -1
- package/build/docs/cache.cjs.map +1 -1
- package/build/docs/cache.d.cts +2 -3
- package/build/docs/cache.d.cts.map +1 -1
- package/build/docs/cache.d.mts +2 -3
- package/build/docs/cache.d.mts.map +1 -1
- package/build/docs/cache.js.map +1 -1
- package/build/docs/generate-metadata-docs.d.cts +1 -2
- package/build/docs/generate-metadata-docs.d.cts.map +1 -1
- package/build/docs/generate-metadata-docs.d.mts +1 -2
- package/build/docs/generate-metadata-docs.d.mts.map +1 -1
- package/build/docs/index.d.cts +3 -3
- package/build/docs/index.d.cts.map +1 -1
- package/build/docs/index.d.mts +3 -3
- package/build/docs/index.d.mts.map +1 -1
- package/build/docs/markdown.d.cts +8 -8
- package/build/docs/markdown.d.cts.map +1 -1
- package/build/docs/markdown.d.mts +8 -8
- package/build/docs/markdown.d.mts.map +1 -1
- package/build/docs/parsing.d.cts +9 -9
- package/build/docs/parsing.d.cts.map +1 -1
- package/build/docs/parsing.d.mts +9 -9
- package/build/docs/parsing.d.mts.map +1 -1
- package/build/findEntityScopes.d.cts +3 -4
- package/build/findEntityScopes.d.cts.map +1 -1
- package/build/findEntityScopes.d.mts +3 -4
- package/build/findEntityScopes.d.mts.map +1 -1
- package/build/foreignKeyOrdering.d.cts +1 -2
- package/build/foreignKeyOrdering.d.cts.map +1 -1
- package/build/foreignKeyOrdering.d.mts +1 -2
- package/build/foreignKeyOrdering.d.mts.map +1 -1
- package/build/generate.d.cts +3 -4
- package/build/generate.d.cts.map +1 -1
- package/build/generate.d.mts +3 -4
- package/build/generate.d.mts.map +1 -1
- package/build/generateEntitiesFile.d.cts +1 -2
- package/build/generateEntitiesFile.d.cts.map +1 -1
- package/build/generateEntitiesFile.d.mts +1 -2
- package/build/generateEntitiesFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.cjs +5 -3
- package/build/generateEntityCodegenFile.cjs.map +1 -1
- package/build/generateEntityCodegenFile.d.cts +3 -4
- package/build/generateEntityCodegenFile.d.cts.map +1 -1
- package/build/generateEntityCodegenFile.d.mts +3 -4
- package/build/generateEntityCodegenFile.d.mts.map +1 -1
- package/build/generateEntityCodegenFile.js +5 -3
- package/build/generateEntityCodegenFile.js.map +1 -1
- package/build/generateEntityFile.d.cts +1 -2
- package/build/generateEntityFile.d.cts.map +1 -1
- package/build/generateEntityFile.d.mts +1 -2
- package/build/generateEntityFile.d.mts.map +1 -1
- package/build/generateEntityTestFile.d.cts +1 -2
- package/build/generateEntityTestFile.d.cts.map +1 -1
- package/build/generateEntityTestFile.d.mts +1 -2
- package/build/generateEntityTestFile.d.mts.map +1 -1
- package/build/generateEnumFile.d.cts +1 -2
- package/build/generateEnumFile.d.cts.map +1 -1
- package/build/generateEnumFile.d.mts +1 -2
- package/build/generateEnumFile.d.mts.map +1 -1
- package/build/generateFactoriesFiles.d.cts +1 -2
- package/build/generateFactoriesFiles.d.cts.map +1 -1
- package/build/generateFactoriesFiles.d.mts +1 -2
- package/build/generateFactoriesFiles.d.mts.map +1 -1
- package/build/generateFlushFunction.d.cts +3 -4
- package/build/generateFlushFunction.d.cts.map +1 -1
- package/build/generateFlushFunction.d.mts +3 -4
- package/build/generateFlushFunction.d.mts.map +1 -1
- package/build/generateMetadataFile.cjs +30 -1
- package/build/generateMetadataFile.cjs.map +1 -1
- package/build/generateMetadataFile.d.cts +2 -3
- package/build/generateMetadataFile.d.cts.map +1 -1
- package/build/generateMetadataFile.d.mts +2 -3
- package/build/generateMetadataFile.d.mts.map +1 -1
- package/build/generateMetadataFile.js +31 -2
- package/build/generateMetadataFile.js.map +1 -1
- package/build/generatePgEnumFile.d.cts +1 -2
- package/build/generatePgEnumFile.d.cts.map +1 -1
- package/build/generatePgEnumFile.d.mts +1 -2
- package/build/generatePgEnumFile.d.mts.map +1 -1
- package/build/index.d.cts +4 -4
- package/build/index.d.cts.map +1 -1
- package/build/index.d.mts +4 -4
- package/build/index.d.mts.map +1 -1
- package/build/inheritance.d.cts +3 -3
- package/build/inheritance.d.cts.map +1 -1
- package/build/inheritance.d.mts +3 -3
- package/build/inheritance.d.mts.map +1 -1
- package/build/installSkills.d.cts +1 -2
- package/build/installSkills.d.cts.map +1 -1
- package/build/installSkills.d.mts +1 -2
- package/build/installSkills.d.mts.map +1 -1
- package/build/keywords.d.cts +1 -2
- package/build/keywords.d.cts.map +1 -1
- package/build/keywords.d.mts +1 -2
- package/build/keywords.d.mts.map +1 -1
- package/build/loadMetadata.d.cts +7 -8
- package/build/loadMetadata.d.cts.map +1 -1
- package/build/loadMetadata.d.mts +7 -8
- package/build/loadMetadata.d.mts.map +1 -1
- package/build/logger.d.cts +3 -4
- package/build/logger.d.cts.map +1 -1
- package/build/logger.d.mts +3 -4
- package/build/logger.d.mts.map +1 -1
- package/build/pgMetadata.d.cts +13 -14
- package/build/pgMetadata.d.cts.map +1 -1
- package/build/pgMetadata.d.mts +13 -14
- package/build/pgMetadata.d.mts.map +1 -1
- package/build/scanEntityFiles.cjs +6 -1
- package/build/scanEntityFiles.cjs.map +1 -1
- package/build/scanEntityFiles.d.cts +2 -3
- package/build/scanEntityFiles.d.cts.map +1 -1
- package/build/scanEntityFiles.d.mts +2 -3
- package/build/scanEntityFiles.d.mts.map +1 -1
- package/build/scanEntityFiles.js +6 -1
- package/build/scanEntityFiles.js.map +1 -1
- package/build/sortForeignKeys.d.cts +1 -2
- package/build/sortForeignKeys.d.cts.map +1 -1
- package/build/sortForeignKeys.d.mts +1 -2
- package/build/sortForeignKeys.d.mts.map +1 -1
- package/build/symbols.cjs +2 -0
- package/build/symbols.cjs.map +1 -1
- package/build/symbols.d.cts +117 -117
- package/build/symbols.d.cts.map +1 -1
- package/build/symbols.d.mts +117 -117
- package/build/symbols.d.mts.map +1 -1
- package/build/symbols.js +2 -1
- package/build/symbols.js.map +1 -1
- package/build/tsdoc.d.cts +1 -2
- package/build/tsdoc.d.cts.map +1 -1
- package/build/tsdoc.d.mts +1 -2
- package/build/tsdoc.d.mts.map +1 -1
- package/build/utils.cjs +1 -0
- package/build/utils.cjs.map +1 -1
- package/build/utils.d.cts +21 -22
- package/build/utils.d.cts.map +1 -1
- package/build/utils.d.mts +21 -22
- package/build/utils.d.mts.map +1 -1
- package/build/utils.js +1 -0
- package/build/utils.js.map +1 -1
- package/package.json +10 -10
- package/skills/joist-test-factories/SKILL.md +93 -6
|
@@ -123,7 +123,7 @@ function inferUniqueConstraints(meta, table) {
|
|
|
123
123
|
/** Returns the queryable field name for a unique constraint column. */
|
|
124
124
|
function fieldNameForColumn(meta, columnName) {
|
|
125
125
|
const primitive = meta.primitives.find((field) => field.columnName === columnName);
|
|
126
|
-
if (primitive && !primitive.derived && !primitive.
|
|
126
|
+
if (primitive && !primitive.derived && !primitive.customSerde) return primitive.fieldName;
|
|
127
127
|
const enumField = meta.enums.find((field) => field.columnName === columnName);
|
|
128
128
|
if (enumField && !enumField.derived && !enumField.isArray) return enumField.fieldName;
|
|
129
129
|
const pgEnum = meta.pgEnums.find((field) => field.columnName === columnName);
|
|
@@ -254,7 +254,8 @@ function newEnumField(config, entity, r, enums) {
|
|
|
254
254
|
ignore,
|
|
255
255
|
enumRows: enums[r.targetTable.name].rows,
|
|
256
256
|
isArray: false,
|
|
257
|
-
hasConfigDefault
|
|
257
|
+
hasConfigDefault,
|
|
258
|
+
hasTransitions: false
|
|
258
259
|
};
|
|
259
260
|
}
|
|
260
261
|
function newEnumArrayField(config, entity, column, enums) {
|
|
@@ -287,7 +288,8 @@ function newEnumArrayField(config, entity, column, enums) {
|
|
|
287
288
|
ignore,
|
|
288
289
|
enumRows: enums[enumTable].rows,
|
|
289
290
|
isArray: true,
|
|
290
|
-
hasConfigDefault
|
|
291
|
+
hasConfigDefault,
|
|
292
|
+
hasTransitions: false
|
|
291
293
|
};
|
|
292
294
|
}
|
|
293
295
|
function newPgEnumField(config, entity, column) {
|
|
@@ -573,6 +575,7 @@ function canonicalizeOtherEntities(db) {
|
|
|
573
575
|
* `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
|
|
574
576
|
* enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
|
|
575
577
|
* would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
|
|
578
|
+
* Polymorphic unions yield to these API names by appending `Poly` until the name is available.
|
|
576
579
|
*
|
|
577
580
|
* Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
|
|
578
581
|
* the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
|
|
@@ -585,6 +588,21 @@ function resolveNameConflicts(config, db) {
|
|
|
585
588
|
}
|
|
586
589
|
for (const pgEnum of Object.values(db.pgEnums)) reserved.add(pgEnum.name);
|
|
587
590
|
for (const meta of db.entities) if (hasNameConflict(meta.name, reserved)) applyEntityNames(meta.entity, reserved);
|
|
591
|
+
for (const meta of db.entities) {
|
|
592
|
+
const keys = Object.keys(entitySymbolNames(meta.name));
|
|
593
|
+
for (const key of keys) reserved.add(meta.entity[key]);
|
|
594
|
+
reserved.add(`${meta.name}Codegen`).add(`${meta.name}Columns`);
|
|
595
|
+
}
|
|
596
|
+
const polymorphics = db.entities.flatMap((meta) => meta.polymorphics);
|
|
597
|
+
const unionNames = new Set(polymorphics.map((poly) => poly.fieldType));
|
|
598
|
+
for (const poly of polymorphics) {
|
|
599
|
+
if (reserved.has(poly.fieldType)) {
|
|
600
|
+
let name = `${poly.fieldType}Poly`;
|
|
601
|
+
while (reserved.has(name) || unionNames.has(name)) name += "Poly";
|
|
602
|
+
poly.fieldType = name;
|
|
603
|
+
}
|
|
604
|
+
reserved.add(poly.fieldType);
|
|
605
|
+
}
|
|
588
606
|
}
|
|
589
607
|
/** Computes the codegen'd type names for an entity, underscoring any that `reserved` already contains. */
|
|
590
608
|
function entitySymbolNames(name, reserved) {
|
|
@@ -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","EnumType","mapSimpleDbTypeToTypescriptType","ormMaintainedFields","isGetterField","isReactiveField","imp","pascalCase","isLargeCollection","parseOrder","softDeletesConfig","isReactiveManyToMany","joinTableHasId","M2ORelation","camelCase","groupBy","Zod"],"sources":["../src/EntityDbMetadata.ts"],"sourcesContent":["import { camelCase, pascalCase, snakeCase } from \"change-case\";\nimport { groupBy } from \"joist-utils\";\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 {\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 \"./pgMetadata.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 PostgreSQL catalog 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 /** Physical columns ignored by entity fields, retained for direct SQL reads and writes. */\n ignoredColumns: PrimitiveField[];\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 const modeledColumns = new Set([\n this.primaryKey.columnName,\n ...this.primitives.map((field) => field.columnName),\n ...this.enums.map((field) => field.columnName),\n ...this.pgEnums.map((field) => field.columnName),\n ...this.manyToOnes.map((field) => field.columnName),\n ...this.polymorphics.flatMap((field) => field.components.map((component) => component.columnName)),\n ]);\n this.ignoredColumns = table.columns\n .filter((column) => !modeledColumns.has(column.name))\n .map((column) => newPhysicalColumn(config, this.entity, column));\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 // Composite keys and unsupported physical arrays still cannot be written 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, ...this.ignoredColumns].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 }\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\n/** Keeps an ignored column's database type without applying entity-only field configuration. */\nfunction newPhysicalColumn(config: Config, entity: Entity, column: Column): PrimitiveField {\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const rawFieldType = column.type instanceof EnumType ? \"string\" : mapSimpleDbTypeToTypescriptType(config, columnType);\n const isArray = column.arrayDimension === 1;\n return {\n kind: \"primitive\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName: primitiveFieldName(column.name),\n columnName: column.name,\n columnType,\n fieldType: isArray ? code`${rawFieldType}[]` : rawFieldType,\n rawFieldType,\n notNull: column.notNull,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: false,\n protected: false,\n unique: false,\n superstruct: undefined,\n zodSchema: undefined,\n customSerde: undefined,\n isArray,\n hasConfigDefault: false,\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;C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BAAgBD,mBAAAA;AAC3B;AAEA,SAAS,gBAAgB,GAAmB;CAE1C,MAAM,CAAC,QAAQ,GAAG,QAAQ,EAAE,MAAM,GAAG;CACrC,OAAOF,QAAAA,OAAO,KAAK,IAAA,GAAGQ,YAAAA,WAAAA,CAAW,MAAM,EAAE,GAAG,KAAK,KAAK,GAAG,GAAG;AAC9D;AAEA,SAAS,cAAc,GAAiB;CACtC,MAAM,SAASR,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","EnumType","mapSimpleDbTypeToTypescriptType","ormMaintainedFields","isGetterField","isReactiveField","imp","pascalCase","isLargeCollection","parseOrder","softDeletesConfig","isReactiveManyToMany","joinTableHasId","M2ORelation","camelCase","groupBy","Zod"],"sources":["../src/EntityDbMetadata.ts"],"sourcesContent":["import { camelCase, pascalCase, snakeCase } from \"change-case\";\nimport { groupBy } from \"joist-utils\";\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 {\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 \"./pgMetadata.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 | \"vector\";\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 =\n | \"boolean\"\n | \"string\"\n | \"number\"\n | \"number[]\"\n | \"Object\"\n | \"bigint\"\n | \"Uint8Array\"\n | 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 /** Whether the entity file calls `config.setTransitions`, `addTransitionRule`, or `addTransitionReaction` on this field, set by `scanEntityFiles`. */\n hasTransitions: 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 PostgreSQL catalog 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 /** Physical columns ignored by entity fields, retained for direct SQL reads and writes. */\n ignoredColumns: PrimitiveField[];\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 const modeledColumns = new Set([\n this.primaryKey.columnName,\n ...this.primitives.map((field) => field.columnName),\n ...this.enums.map((field) => field.columnName),\n ...this.pgEnums.map((field) => field.columnName),\n ...this.manyToOnes.map((field) => field.columnName),\n ...this.polymorphics.flatMap((field) => field.components.map((component) => component.columnName)),\n ]);\n this.ignoredColumns = table.columns\n .filter((column) => !modeledColumns.has(column.name))\n .map((column) => newPhysicalColumn(config, this.entity, column));\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 // Composite keys and unsupported physical arrays still cannot be written 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, ...this.ignoredColumns].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 }\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.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\n/** Keeps an ignored column's database type without applying entity-only field configuration. */\nfunction newPhysicalColumn(config: Config, entity: Entity, column: Column): PrimitiveField {\n const columnType = (column.type.shortName || column.type.name) as DatabaseColumnType;\n const rawFieldType = column.type instanceof EnumType ? \"string\" : mapSimpleDbTypeToTypescriptType(config, columnType);\n const isArray = column.arrayDimension === 1;\n return {\n kind: \"primitive\",\n columnOwner: entity,\n columnNotNull: column.notNull,\n fieldName: primitiveFieldName(column.name),\n columnName: column.name,\n columnType,\n fieldType: isArray ? code`${rawFieldType}[]` : rawFieldType,\n rawFieldType,\n notNull: column.notNull,\n columnDefault: column.default,\n columnGenerated: column.isGenerated,\n derived: false,\n protected: false,\n unique: false,\n superstruct: undefined,\n zodSchema: undefined,\n customSerde: undefined,\n isArray,\n hasConfigDefault: false,\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 hasTransitions: false, // 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 hasTransitions: false,\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 * Polymorphic unions yield to these API names by appending `Poly` until the name is available.\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 // Potentially rename poly types, like a `BookParent = PolyOne | PolyTwo | PolyThree`, if the `BookParent`\n // name would conflict with existing generated type names. Specifically, our query-scopes feature\n // creates a `BookScope` type that, if the user also adds a `scope_*` poly, would have the\n // same name as the poly type.\n //\n // Here we detect that, let the scope-feature `BookScope` type win, and rename the poly type to\n // `BookScopePoly`, appending `Poly` again if that name is also taken.\n for (const meta of db.entities) {\n const keys = Object.keys(entitySymbolNames(meta.name)) as (keyof ReturnType<typeof entitySymbolNames>)[];\n for (const key of keys) reserved.add(meta.entity[key]);\n reserved.add(`${meta.name}Codegen`).add(`${meta.name}Columns`);\n }\n const polymorphics = db.entities.flatMap((meta) => meta.polymorphics);\n const unionNames = new Set(polymorphics.map((poly) => poly.fieldType));\n for (const poly of polymorphics) {\n if (reserved.has(poly.fieldType)) {\n // I.e. Comment.scope uses CommentScopePoly, leaving CommentScope for query scopes.\n let name = `${poly.fieldType}Poly`;\n while (reserved.has(name) || unionNames.has(name)) name += \"Poly\";\n poly.fieldType = name;\n }\n reserved.add(poly.fieldType);\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;;AAmR7B,IAAa,mBAAb,MAA8B;CAC5B;CACA;CACA;CAC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
|
import { Code, Import } from "ts-poet";
|
|
5
5
|
//#region src/EntityDbMetadata.d.ts
|
|
6
6
|
/** All the entities + enums in our database. */
|
|
7
|
-
interface DbMetadata {
|
|
7
|
+
export interface DbMetadata {
|
|
8
8
|
entities: EntityDbMetadata[];
|
|
9
9
|
/** Type name i.e. `Author` to metadata. */
|
|
10
10
|
entitiesByName: Record<string, EntityDbMetadata>;
|
|
@@ -16,7 +16,7 @@ interface DbMetadata {
|
|
|
16
16
|
totalTables: number;
|
|
17
17
|
}
|
|
18
18
|
/** Codegen-time metadata about a given domain entity. */
|
|
19
|
-
type Entity = {
|
|
19
|
+
export type Entity = {
|
|
20
20
|
name: string;
|
|
21
21
|
/** The _type_ symbol pointing to the entity itself. */
|
|
22
22
|
type: Import;
|
|
@@ -56,7 +56,7 @@ type Entity = {
|
|
|
56
56
|
/** i.e. `AuthorScopes`. */
|
|
57
57
|
scopesName: string;
|
|
58
58
|
};
|
|
59
|
-
type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange";
|
|
59
|
+
export type DatabaseColumnType = "boolean" | "int" | "uuid" | "numeric" | "smallint" | "integer" | "bigint" | "decimal" | "real" | "smallserial" | "serial" | "bigserial" | "double precision" | "text" | "citext" | "character varying" | "varchar" | "time without time zone" | "timestamp with time zone" | "timestamp without time zone" | "date" | "jsonb" | "bytea" | "tsvector" | "tstzrange" | "vector";
|
|
60
60
|
/**
|
|
61
61
|
* A logical entity field.
|
|
62
62
|
*
|
|
@@ -66,8 +66,8 @@ interface Field {
|
|
|
66
66
|
fieldName: string;
|
|
67
67
|
ignore?: boolean;
|
|
68
68
|
}
|
|
69
|
-
type PrimitiveTypescriptType = "boolean" | "string" | "number" | "Object" | "bigint" | "Uint8Array" | Code;
|
|
70
|
-
type PrimitiveField = Field & {
|
|
69
|
+
export type PrimitiveTypescriptType = "boolean" | "string" | "number" | "number[]" | "Object" | "bigint" | "Uint8Array" | Code;
|
|
70
|
+
export type PrimitiveField = Field & {
|
|
71
71
|
kind: "primitive";
|
|
72
72
|
columnName: string;
|
|
73
73
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -90,7 +90,7 @@ type PrimitiveField = Field & {
|
|
|
90
90
|
hasConfigDefault: boolean;
|
|
91
91
|
lazy?: boolean;
|
|
92
92
|
};
|
|
93
|
-
type EnumField = Field & {
|
|
93
|
+
export type EnumField = Field & {
|
|
94
94
|
kind: "enum";
|
|
95
95
|
columnName: string;
|
|
96
96
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -108,8 +108,10 @@ type EnumField = Field & {
|
|
|
108
108
|
notNull: boolean;
|
|
109
109
|
isArray: boolean;
|
|
110
110
|
hasConfigDefault: boolean;
|
|
111
|
+
/** Whether the entity file calls `config.setTransitions`, `addTransitionRule`, or `addTransitionReaction` on this field, set by `scanEntityFiles`. */
|
|
112
|
+
hasTransitions: boolean;
|
|
111
113
|
};
|
|
112
|
-
type PgEnumField = Field & {
|
|
114
|
+
export type PgEnumField = Field & {
|
|
113
115
|
kind: "pg-enum";
|
|
114
116
|
columnName: string;
|
|
115
117
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -127,7 +129,7 @@ type PgEnumField = Field & {
|
|
|
127
129
|
hasConfigDefault: boolean;
|
|
128
130
|
};
|
|
129
131
|
/** I.e. a `Book.author` reference pointing to an `Author`. */
|
|
130
|
-
type ManyToOneField = Field & {
|
|
132
|
+
export type ManyToOneField = Field & {
|
|
131
133
|
kind: "m2o";
|
|
132
134
|
columnName: string;
|
|
133
135
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
@@ -146,7 +148,7 @@ type ManyToOneField = Field & {
|
|
|
146
148
|
onDelete: Action;
|
|
147
149
|
};
|
|
148
150
|
/** I.e. a `Author.books` collection. */
|
|
149
|
-
type OneToManyField = Field & {
|
|
151
|
+
export type OneToManyField = Field & {
|
|
150
152
|
kind: "o2m";
|
|
151
153
|
singularName: string;
|
|
152
154
|
otherEntity: Entity;
|
|
@@ -161,14 +163,14 @@ type OneToManyField = Field & {
|
|
|
161
163
|
softDeletes: "include" | "exclude" | undefined;
|
|
162
164
|
};
|
|
163
165
|
/** I.e. a `Author.image` reference when `image.author_id` is unique. */
|
|
164
|
-
type OneToOneField = Field & {
|
|
166
|
+
export type OneToOneField = Field & {
|
|
165
167
|
kind: "o2o";
|
|
166
168
|
otherEntity: Entity;
|
|
167
169
|
otherFieldName: string;
|
|
168
170
|
otherColumnName: string;
|
|
169
171
|
otherColumnNotNull: boolean;
|
|
170
172
|
};
|
|
171
|
-
type ManyToManyField = Field & {
|
|
173
|
+
export type ManyToManyField = Field & {
|
|
172
174
|
kind: "m2m";
|
|
173
175
|
joinTableName: string;
|
|
174
176
|
singularName: string;
|
|
@@ -184,7 +186,7 @@ type ManyToManyField = Field & {
|
|
|
184
186
|
hasJoinTableId: boolean;
|
|
185
187
|
};
|
|
186
188
|
/** I.e. a `Publisher.logoColors` m2m to the `color` enum table, backed by `publisher_logo_colors`. */
|
|
187
|
-
type ManyToManyEnumField = Field & {
|
|
189
|
+
export type ManyToManyEnumField = Field & {
|
|
188
190
|
kind: "m2mEnum";
|
|
189
191
|
joinTableName: string;
|
|
190
192
|
/** The entity's FK column, e.g. `publisher_id`. */
|
|
@@ -200,7 +202,7 @@ type ManyToManyEnumField = Field & {
|
|
|
200
202
|
hasJoinTableId: boolean;
|
|
201
203
|
};
|
|
202
204
|
/** I.e. a `Comment.parent` reference that groups `comments.parent_book_id` and `comments.parent_book_review_id`. */
|
|
203
|
-
type PolymorphicField = Field & {
|
|
205
|
+
export type PolymorphicField = Field & {
|
|
204
206
|
kind: "poly";
|
|
205
207
|
fieldType: string;
|
|
206
208
|
notNull: boolean;
|
|
@@ -208,7 +210,7 @@ type PolymorphicField = Field & {
|
|
|
208
210
|
components: PolymorphicFieldComponent[];
|
|
209
211
|
};
|
|
210
212
|
/** A column such as `parent_book_id` or `parent_book_review_id`. */
|
|
211
|
-
type PolymorphicFieldComponent = {
|
|
213
|
+
export type PolymorphicFieldComponent = {
|
|
212
214
|
columnName: string;
|
|
213
215
|
/** Physical table owner, unchanged by domain inheritance specialization. */
|
|
214
216
|
columnOwner: Entity;
|
|
@@ -218,12 +220,12 @@ type PolymorphicFieldComponent = {
|
|
|
218
220
|
constraintName: string;
|
|
219
221
|
notNull: false;
|
|
220
222
|
};
|
|
221
|
-
type FieldNameOverrides = {
|
|
223
|
+
export type FieldNameOverrides = {
|
|
222
224
|
fieldName?: string;
|
|
223
225
|
otherFieldName?: string;
|
|
224
226
|
};
|
|
225
227
|
/** Adapts PostgreSQL catalog metadata into our specific ORM types. */
|
|
226
|
-
declare class EntityDbMetadata {
|
|
228
|
+
export declare class EntityDbMetadata {
|
|
227
229
|
entity: Entity;
|
|
228
230
|
primaryKey: PrimitiveField;
|
|
229
231
|
primitives: PrimitiveField[];
|
|
@@ -265,16 +267,16 @@ declare class EntityDbMetadata {
|
|
|
265
267
|
get nonDeferredManyToManyFks(): Array<ManyToManyField>;
|
|
266
268
|
}
|
|
267
269
|
/** Finds the field name for o2o side of a o2o/m2o. */
|
|
268
|
-
declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
|
|
269
|
-
declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
|
|
270
|
-
declare function manyToManyName(column: Column): string;
|
|
270
|
+
export declare function oneToOneName(config: Config, refEntity: Entity, keyEntity: Entity, r: M2ORelation | O2MRelation): string;
|
|
271
|
+
export declare function referenceName(config: Config, entity: Entity, r: M2ORelation | O2MRelation): string;
|
|
272
|
+
export declare function manyToManyName(column: Column): string;
|
|
271
273
|
/** Returns the collection name to use on `entity` when referring to `otherEntity`s. */
|
|
272
|
-
declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
|
|
274
|
+
export declare function collectionName(config: Config, singleEntity: Entity, collectionEntity: Entity, r: M2ORelation | O2MRelation | M2MRelation): {
|
|
273
275
|
fieldName: string;
|
|
274
276
|
singularName: string;
|
|
275
277
|
};
|
|
276
|
-
declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
|
|
277
|
-
declare function makeEntity(entityName: string): Entity;
|
|
278
|
+
export declare function failIfOverlappingFieldNames(entity: EntityDbMetadata): void;
|
|
279
|
+
export declare function makeEntity(entityName: string): Entity;
|
|
278
280
|
/**
|
|
279
281
|
* Collapses the per-relation `otherEntity` copies down to the one primary `Entity` per name.
|
|
280
282
|
*
|
|
@@ -284,18 +286,19 @@ declare function makeEntity(entityName: string): Entity;
|
|
|
284
286
|
*
|
|
285
287
|
* Must run after inheritance, since STI/CTI specialization both adds and re-points `otherEntity`s.
|
|
286
288
|
*/
|
|
287
|
-
declare function canonicalizeOtherEntities(db: DbMetadata): void;
|
|
289
|
+
export declare function canonicalizeOtherEntities(db: DbMetadata): void;
|
|
288
290
|
/**
|
|
289
291
|
* Rewrites codegen'd type names that collide with another exported type name.
|
|
290
292
|
*
|
|
291
293
|
* `makeEntity` defaults each name to the conventional `${name}<Suffix>`, but if a separate entity or
|
|
292
294
|
* enum is literally named e.g. `AuthorScope` or `AuthorOrder`, our generated type of the same name
|
|
293
295
|
* would collide with it, so we fall back to `Author_Scope` / `Author_Order`.
|
|
296
|
+
* Polymorphic unions yield to these API names by appending `Poly` until the name is available.
|
|
294
297
|
*
|
|
295
298
|
* Relies on `canonicalizeOtherEntities` having run, so mutating each primary `meta.entity` also updates
|
|
296
299
|
* the `otherEntity` references that point at it (e.g. `Book.author: AuthorId` follows `Author`'s rename).
|
|
297
300
|
*/
|
|
298
|
-
declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
|
|
301
|
+
export declare function resolveNameConflicts(config: Config, db: DbMetadata): void;
|
|
299
302
|
//#endregion
|
|
300
|
-
export {
|
|
303
|
+
export {};
|
|
301
304
|
//# sourceMappingURL=EntityDbMetadata.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDbMetadata.d.cts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"EntityDbMetadata.d.cts","names":[],"sources":["../src/EntityDbMetadata.ts"],"mappings":";;;;;;iBAmDiB;EACf,UAAU;;EAEV,gBAAgB,eAAe;EAC/B,OAAO;EACP,SAAS;EACT;;EAEA;EACA;;;YAIU;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;;YAGU;;;;;;UAiCF;EACR;EACA;;YAGU,8GAQR;YAEQ,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;;YAGU,YAAY;EACtB;EACA;;EAEA,aAAa;EACb,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,gBAAgB;EAChB,iBAAiB;EACjB,UAAU;EACV;EACA;EACA;;EAEA;;YAGU,cAAc;EACxB;EACA;;EAEA,aAAa;EACb;EACA;EACA;;EAEA;;EAEA;EACA,UAAU;EACV;EACA;EACA;;;YAIU,iBAAiB;EAC3B;EACA;;EAEA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;EACA,UAAU;;;YAIA,iBAAiB;EAC3B;EACA;EACA,aAAa;EACb;EACA;EACA;EACA;EACA;IAAW;IAAe;;EAC1B;;;YAIU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