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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/build/EntityDbMetadata.cjs +6 -0
  2. package/build/EntityDbMetadata.cjs.map +1 -1
  3. package/build/EntityDbMetadata.d.cts +2 -0
  4. package/build/EntityDbMetadata.d.cts.map +1 -1
  5. package/build/EntityDbMetadata.d.mts +2 -0
  6. package/build/EntityDbMetadata.d.mts.map +1 -1
  7. package/build/EntityDbMetadata.js +6 -0
  8. package/build/EntityDbMetadata.js.map +1 -1
  9. package/build/generate.cjs +1 -0
  10. package/build/generate.cjs.map +1 -1
  11. package/build/generate.js +2 -1
  12. package/build/generate.js.map +1 -1
  13. package/build/generateEntityCodegenFile.cjs +13 -10
  14. package/build/generateEntityCodegenFile.cjs.map +1 -1
  15. package/build/generateEntityCodegenFile.d.cts.map +1 -1
  16. package/build/generateEntityCodegenFile.d.mts.map +1 -1
  17. package/build/generateEntityCodegenFile.js +13 -10
  18. package/build/generateEntityCodegenFile.js.map +1 -1
  19. package/build/generateMetadataFile.cjs +58 -44
  20. package/build/generateMetadataFile.cjs.map +1 -1
  21. package/build/generateMetadataFile.d.cts +3 -1
  22. package/build/generateMetadataFile.d.cts.map +1 -1
  23. package/build/generateMetadataFile.d.mts +3 -1
  24. package/build/generateMetadataFile.d.mts.map +1 -1
  25. package/build/generateMetadataFile.js +59 -46
  26. package/build/generateMetadataFile.js.map +1 -1
  27. package/build/inheritance.cjs +28 -0
  28. package/build/inheritance.cjs.map +1 -1
  29. package/build/inheritance.d.cts +1 -0
  30. package/build/inheritance.d.cts.map +1 -1
  31. package/build/inheritance.d.mts +1 -0
  32. package/build/inheritance.d.mts.map +1 -1
  33. package/build/inheritance.js +28 -0
  34. package/build/inheritance.js.map +1 -1
  35. package/build/symbols.cjs +10 -0
  36. package/build/symbols.cjs.map +1 -1
  37. package/build/symbols.d.cts +6 -1
  38. package/build/symbols.d.cts.map +1 -1
  39. package/build/symbols.d.mts +6 -1
  40. package/build/symbols.d.mts.map +1 -1
  41. package/build/symbols.js +6 -1
  42. package/build/symbols.js.map +1 -1
  43. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"generateMetadataFile.js","names":[],"sources":["../src/generateMetadataFile.ts"],"sourcesContent":["import { type Code, type Import, code, imp } from \"ts-poet\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DatabaseColumnType,\n type DbMetadata,\n type EntityDbMetadata,\n type OneToManyField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\nimport {\n BigIntSerde,\n CustomSerdeAdapter,\n DateSerde,\n DecimalToNumberSerde,\n EntityMetadata,\n EnumArrayFieldSerde,\n EnumFieldSerde,\n JsonSerde,\n KeySerde,\n PlainDateSerde,\n PlainDateTimeSerde,\n PlainTimeSerde,\n PolymorphicKeySerde,\n PrimitiveSerde,\n SuperstructSerde,\n ZodSerde,\n ZonedDateTimeSerde,\n} from \"./symbols.ts\";\nimport { mapSimpleDbTypeToTypescriptType, q } from \"./utils.ts\";\n\nexport function generateMetadataFile(config: Config, dbMeta: DbMetadata, meta: EntityDbMetadata): Code {\n const { entity, createdAt, updatedAt, deletedAt } = meta;\n\n const fields = generateFields(config, meta);\n\n Object.values(fields).forEach((code) => code.asOneline());\n\n const maybeBaseType = meta.baseClassName ? `\"${meta.baseClassName}\"` : undefined;\n // We want to put inheritanceType: sti/cti onto base classes as well\n const maybeInheritanceType = meta.inheritanceType ? `inheritanceType: \"${meta.inheritanceType}\",` : \"\";\n const maybeStiColumn = meta.stiDiscriminatorField ? `stiDiscriminatorField: \"${meta.stiDiscriminatorField}\",` : \"\";\n const maybeStiValue = meta.stiDiscriminatorValue ? `stiDiscriminatorValue: ${meta.stiDiscriminatorValue},` : \"\";\n const maybeCtiAbstract = meta.abstract ? `ctiAbstract: ${meta.abstract},` : \"\";\n // Force subtype `timestampFields` to be `undefined` to ensure all runtime code is reading from the baseMeta values.\n // Force subtype `timestampFields` to be `undefined` to ensure all runtime code is reading from the baseMeta values.\n const maybeTimestampConfig = meta.baseClassName\n ? code`undefined`\n : code`\n {\n createdAt: ${q(createdAt?.fieldName)},\n updatedAt: ${q(updatedAt?.fieldName)},\n deletedAt: ${q(deletedAt?.fieldName)},\n }\n `;\n const maybeInsertionOrder = meta.nonDeferredFkOrder !== 0 ? `nonDeferredFkOrder: ${meta.nonDeferredFkOrder},` : ``;\n const uniqueBy = getUniqueBy(config, meta);\n const maybeUniqueBy = uniqueBy.length > 0 ? code`uniqueBy: ${JSON.stringify(uniqueBy)},` : code``;\n\n return code`\n export const ${entity.metaName}: ${EntityMetadata}<${entity.name}> = {\n cstr: ${entity.typeForMetadataFile},\n type: \"${entity.name}\",\n baseType: ${maybeBaseType}, ${maybeInheritanceType} ${maybeStiColumn} ${maybeStiValue} ${maybeCtiAbstract}\n idType: \"${config.idType ?? \"tagged-string\"}\",\n idDbType: \"${meta.primaryKey.columnType}\",\n tagName: \"${meta.tagName}\",\n tableName: \"${meta.tableName}\",\n supportsEmExecute: ${!meta.inheritanceType && meta.supportsEmExecute === true},\n fields: ${fields},\n columns: ${Object.fromEntries([\n [\"id\", { fieldName: \"id\" }],\n ...[...meta.primitives, ...meta.enums, ...meta.pgEnums, ...meta.manyToOnes].map((field) => [\n field.columnName,\n { fieldName: field.fieldName },\n ]),\n ...meta.polymorphics.flatMap((field) =>\n field.components.map((component) => [component.columnName, { fieldName: field.fieldName }]),\n ),\n ])},\n allFields: {},\n orderBy: ${q(config.entities[meta.name]?.orderBy)},\n timestampFields: ${maybeTimestampConfig},\n config: ${entity.configConst},\n factory: ${imp(`new${entity.name}@./entities.ts`)},\n baseTypes: [],\n subTypes: [], ${maybeInsertionOrder} ${maybeUniqueBy}\n };\n\n (${entity.typeForMetadataFile} as any).metadata = ${entity.metaName};\n `;\n}\n\n/** Returns configured identities plus conservative database-backed unique identities. */\nfunction getUniqueBy(config: Config, meta: EntityDbMetadata): string[][] {\n const uniqueBy = config.entities[meta.name]?.uniqueBy ?? [];\n const seen = new Set<string>();\n return [...uniqueBy, ...(meta.uniqueConstraints ?? [])].filter((fields) => {\n const key = fields.join(\"\\u0000\");\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n\nfunction generateFields(config: Config, dbMetadata: EntityDbMetadata): Record<string, Code> {\n const fields: Record<string, Code> = {};\n\n fields[\"id\"] = code`\n {\n kind: \"primaryKey\",\n fieldName: \"id\",\n fieldIdName: undefined,\n required: true,\n serde: new ${KeySerde}(\"${dbMetadata.tagName}\", \"id\", \"id\", \"${dbMetadata.primaryKey.columnType}\", ${columnOptions(dbMetadata.primaryKey)}),\n immutable: true,\n }\n `;\n\n dbMetadata.primitives.forEach((p) => {\n const { fieldName, derived, columnName, columnType, superstruct, zodSchema, customSerde, isArray } = p;\n const column = columnOptions(p);\n let serde: Code;\n if (customSerde) {\n serde = isArray\n ? code`new ${CustomSerdeAdapter}(\"${fieldName}\", \"${columnName}\", \"${columnType}[]\", ${customSerde}, true, ${!p.notNull}, ${column})`\n : code`new ${CustomSerdeAdapter}(\"${fieldName}\", \"${columnName}\", \"${columnType}\", ${customSerde}, false, false, ${column})`;\n } else if (superstruct) {\n serde = code`new ${SuperstructSerde}(\"${fieldName}\", \"${columnName}\", ${superstruct}, ${column})`;\n } else if (zodSchema) {\n serde = code`new ${ZodSerde}(\"${fieldName}\", \"${columnName}\", ${zodSchema}, ${column})`;\n } else if (columnType === \"numeric\" || columnType === \"decimal\") {\n serde = isArray\n ? code`new ${DecimalToNumberSerde}(\"${fieldName}\", \"${columnName}\", true, ${!p.notNull}, ${column})`\n : code`new ${DecimalToNumberSerde}(\"${fieldName}\", \"${columnName}\", false, false, ${column})`;\n } else if (columnType === \"jsonb\") {\n serde = code`new ${JsonSerde}(\"${fieldName}\", \"${columnName}\", ${column})`;\n } else if (p.rawFieldType === \"bigint\") {\n serde = isArray\n ? code`new ${BigIntSerde}(\"${fieldName}\", \"${columnName}\", true, ${!p.notNull}, ${column})`\n : code`new ${BigIntSerde}(\"${fieldName}\", \"${columnName}\", false, false, ${column})`;\n } else {\n let serdeType: Import;\n if (columnType === \"date\") {\n serdeType = config.temporal ? PlainDateSerde : DateSerde;\n } else if (columnType === \"timestamp without time zone\") {\n serdeType = config.temporal ? PlainDateTimeSerde : DateSerde;\n } else if (columnType === \"timestamp with time zone\") {\n serdeType = config.temporal ? ZonedDateTimeSerde : DateSerde;\n } else if (columnType === \"time without time zone\") {\n serdeType = config.temporal ? PlainTimeSerde : PrimitiveSerde;\n } else {\n serdeType = PrimitiveSerde;\n }\n serde = isArray\n ? code`new ${serdeType}(\"${fieldName}\", \"${columnName}\", \"${columnType}[]\", true, ${!p.notNull}, ${column})`\n : code`new ${serdeType}(\"${fieldName}\", \"${columnName}\", \"${columnType}\", false, false, ${column})`;\n }\n const extras = columnType === \"citext\" ? code`citext: true,` : \"\";\n fields[fieldName] = code`\n {\n kind: \"primitive\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n derived: ${!derived ? false : `\"${derived}\"`},\n required: ${!derived && p.notNull},\n protected: ${p.protected},\n type: ${typeof p.rawFieldType === \"string\" ? `\"${p.rawFieldType}\"` : p.rawFieldType},\n serde: ${serde},\n immutable: false,\n ${p.lazy ? code`lazy: true,` : \"\"}\n ${extras}\n ${maybeDefault(p)}\n ${maybeSanitize(config, p)}\n }`;\n });\n\n // Treat native enums as primitives\n dbMetadata.pgEnums.forEach((p) => {\n const { columnName, fieldName, notNull, dbType } = p;\n fields[fieldName] = code`\n {\n kind: \"primitive\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n derived: false,\n required: ${notNull},\n protected: false,\n type: \"string\",\n serde: new ${PrimitiveSerde}(\"${fieldName}\", \"${columnName}\", \"${dbType}\", false, false, ${columnOptions(p)}),\n immutable: false,\n ${maybeDefault(p)}\n }`;\n });\n\n dbMetadata.enums.forEach((field) => {\n const { fieldName, enumDetailType, notNull, isArray, columnName, columnType, derived } = field;\n const serdeType = isArray ? EnumArrayFieldSerde : EnumFieldSerde;\n const columnTypeWithArray = `${columnType}${isArray ? \"[]\" : \"\"}`;\n const maybeIsNullable = isArray ? `, ${!notNull}` : \"\";\n fields[fieldName] = code`\n {\n kind: \"enum\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n required: ${notNull},\n derived: ${!derived ? false : `\"${derived}\"`},\n enumDetailType: ${enumDetailType},\n serde: new ${serdeType}(\"${fieldName}\", \"${columnName}\", \"${columnTypeWithArray}\"${maybeIsNullable}, ${enumDetailType}, ${columnOptions(field)}),\n immutable: false,\n ${maybeDefault(field)}\n }\n `;\n });\n\n dbMetadata.manyToOnes.forEach((m2o) => {\n const { fieldName, columnName, notNull, otherEntity, otherFieldName, derived, dbType } = m2o;\n const otherTagName = config.entities[otherEntity.name].tag;\n fields[fieldName] = code`\n {\n kind: \"m2o\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${fieldName}Id\",\n derived: ${!derived ? false : `\"${derived}\"`},\n required: ${notNull},\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n serde: new ${KeySerde}(\"${otherTagName}\", \"${fieldName}\", \"${columnName}\", \"${dbType}\", ${columnOptions(m2o)}),\n immutable: false,\n ${maybeDefault(m2o)}\n }\n `;\n });\n\n dbMetadata.oneToManys.forEach((o2m) => {\n const { fieldName, singularName, otherEntity, otherFieldName, otherColumnName } = o2m;\n fields[fieldName] = code`\n {\n kind: \"o2m\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${singularName}Ids\",\n required: false,\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n otherColumnName: \"${otherColumnName}\",\n serde: undefined,\n immutable: false,\n ${maybeOrderBy(o2m)}\n ${maybeSoftDeletes(o2m)}\n }\n `;\n });\n\n dbMetadata.largeOneToManys.forEach((o2m) => {\n const { fieldName, singularName, otherEntity, otherFieldName, otherColumnName } = o2m;\n fields[fieldName] = code`\n {\n kind: \"lo2m\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${singularName}Ids\",\n required: false,\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n otherColumnName: \"${otherColumnName}\",\n serde: undefined,\n immutable: false,\n }\n `;\n });\n\n dbMetadata.manyToManys.forEach((m2m) => {\n const { fieldName, singularName, otherEntity, otherFieldName, derived } = m2m;\n fields[fieldName] = code`\n {\n kind: \"m2m\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${singularName}Ids\",\n required: false,\n derived: ${derived === \"async\" ? `\"async\"` : derived === \"otherSide\" ? `\"otherSide\"` : \"false\"},\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n serde: undefined,\n immutable: false,\n joinTableName: \"${m2m.joinTableName}\",\n columnNames: [\"${m2m.columnName}\", \"${m2m.otherColumnName}\"],\n hasJoinTableId: ${m2m.hasJoinTableId},\n ${maybeSoftDeletes(m2m)}\n }\n `;\n });\n\n dbMetadata.manyToManyEnums.forEach((m2m) => {\n const { fieldName, enumDetailType } = m2m;\n fields[fieldName] = code`\n {\n kind: \"m2mEnum\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n required: false,\n derived: false,\n enumDetailType: ${enumDetailType},\n serde: undefined,\n immutable: false,\n joinTableName: \"${m2m.joinTableName}\",\n columnNames: [\"${m2m.columnName}\", \"${m2m.otherColumnName}\"],\n hasJoinTableId: ${m2m.hasJoinTableId},\n }\n `;\n });\n\n dbMetadata.oneToOnes.forEach((o2o) => {\n const { fieldName, otherEntity, otherFieldName, otherColumnName } = o2o;\n fields[fieldName] = code`\n {\n kind: \"o2o\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${fieldName}Id\",\n required: false,\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n otherColumnName: \"${otherColumnName}\",\n serde: undefined,\n immutable: false,\n }\n `;\n });\n\n dbMetadata.polymorphics.forEach((p) => {\n const { fieldName, notNull, components } = p;\n fields[fieldName] = code`\n {\n kind: \"poly\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${fieldName}Id\",\n required: ${notNull},\n components: [${components.map(\n ({ otherFieldName, otherEntity, columnName }) => code`\n {\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n columnName: \"${columnName}\",\n },`,\n )}],\n serde: new ${PolymorphicKeySerde}(() => ${dbMetadata.entity.metaName}, \"${fieldName}\"),\n immutable: false,\n }\n `;\n });\n\n return fields;\n}\n\n/** Emits constructor options using codegen's existing column facts. */\nfunction columnOptions(\n column: Pick<PrimitiveField, \"columnNotNull\" | \"columnGenerated\"> & Partial<Pick<PrimitiveField, \"columnDefault\">>,\n): Code {\n return code`{ sqlNullable: ${!column.columnNotNull}, hasDefault: ${column.columnDefault != null && !column.columnGenerated}, isGenerated: ${column.columnGenerated} }`;\n}\n\nfunction maybeDefault(f: { hasConfigDefault: boolean; columnDefault?: number | boolean | string | null }): Code | \"\" {\n return f.hasConfigDefault ? code`default: \"config\",` : f.columnDefault != null ? code`default: \"schema\",` : \"\";\n}\n\nfunction maybeOrderBy(f: OneToManyField): Code | \"\" {\n return f.orderBy ? code`orderBy: { field: \"${f.orderBy.field}\", direction: \"${f.orderBy.direction}\" },` : \"\";\n}\n\n/** Emits the `softDeletes` config, i.e. `softDeletes: \"include\",`, for relations that opt out of hiding soft-deletes. */\nfunction maybeSoftDeletes(f: { softDeletes: \"include\" | \"exclude\" | undefined }): Code | \"\" {\n return f.softDeletes ? code`softDeletes: \"${f.softDeletes}\",` : \"\";\n}\n\n/** We sanitize/cleanStringValue all varchars, unless opted out by the column default/arrays/custom serdes. */\nfunction maybeSanitize(\n config: Config,\n f: { columnType: DatabaseColumnType; columnDefault?: any; isArray: boolean; customSerde: any },\n): Code | \"\" {\n // Only strings need to maybe turn off their cleanStringValue sanitization, if the default=\"\" or its an array\n return isString(config, f.columnType) && (f.columnDefault === \"''\" || f.isArray || f.customSerde)\n ? code`sanitize: false,`\n : \"\";\n}\n\nfunction isString(config: Config, columnType: DatabaseColumnType): boolean {\n return mapSimpleDbTypeToTypescriptType(config, columnType) === \"string\";\n}\n"],"mappings":";;;;;;AA+BA,SAAgB,qBAAqB,QAAgB,QAAoB,MAA8B;CACrG,MAAM,EAAE,QAAQ,WAAW,WAAW,cAAc;CAEpD,MAAM,SAAS,eAAe,QAAQ,IAAI;CAE1C,OAAO,OAAO,MAAM,CAAC,CAAC,SAAS,SAAS,KAAK,UAAU,CAAC;CAExD,MAAM,gBAAgB,KAAK,gBAAgB,IAAI,KAAK,cAAc,KAAK,KAAA;CAEvE,MAAM,uBAAuB,KAAK,kBAAkB,qBAAqB,KAAK,gBAAgB,MAAM;CACpG,MAAM,iBAAiB,KAAK,wBAAwB,2BAA2B,KAAK,sBAAsB,MAAM;CAChH,MAAM,gBAAgB,KAAK,wBAAwB,0BAA0B,KAAK,sBAAsB,KAAK;CAC7G,MAAM,mBAAmB,KAAK,WAAW,gBAAgB,KAAK,SAAS,KAAK;CAG5E,MAAM,uBAAuB,KAAK,gBAC9B,IAAI,cACJ,IAAI;;mBAES,EAAE,WAAW,SAAS,EAAE;mBACxB,EAAE,WAAW,SAAS,EAAE;mBACxB,EAAE,WAAW,SAAS,EAAE;;;CAGzC,MAAM,sBAAsB,KAAK,uBAAuB,IAAI,uBAAuB,KAAK,mBAAmB,KAAK;CAChH,MAAM,WAAW,YAAY,QAAQ,IAAI;CACzC,MAAM,gBAAgB,SAAS,SAAS,IAAI,IAAI,aAAa,KAAK,UAAU,QAAQ,EAAE,KAAK,IAAI;CAE/F,OAAO,IAAI;mBACM,OAAO,SAAS,IAAI,eAAe,GAAG,OAAO,KAAK;cACvD,OAAO,oBAAoB;eAC1B,OAAO,KAAK;kBACT,cAAc,IAAI,qBAAqB,GAAG,eAAe,GAAG,cAAc,GAAG,iBAAiB;iBAC/F,OAAO,UAAU,gBAAgB;mBAC/B,KAAK,WAAW,WAAW;kBAC5B,K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IAAI,iBAAiB,EAAE,YAAY,MAAM;AAClE;;AAGA,SAAS,cACP,QACA,GACW;CAEX,OAAO,SAAS,QAAQ,EAAE,UAAU,MAAM,EAAE,kBAAkB,QAAQ,EAAE,WAAW,EAAE,eACjF,IAAI,qBACJ;AACN;AAEA,SAAS,SAAS,QAAgB,YAAyC;CACzE,OAAO,gCAAgC,QAAQ,UAAU,MAAM;AACjE"}
1
+ {"version":3,"file":"generateMetadataFile.js","names":[],"sources":["../src/generateMetadataFile.ts"],"sourcesContent":["import { type Code, type Import, code, imp } from \"ts-poet\";\n\nimport { type Config } from \"./config.ts\";\nimport {\n type DatabaseColumnType,\n type DbMetadata,\n type EntityDbMetadata,\n type OneToManyField,\n type PrimitiveField,\n} from \"./EntityDbMetadata.ts\";\nimport {\n BigIntSerde,\n Column,\n ColumnDescriptors,\n CustomSerdeAdapter,\n DateSerde,\n DecimalToNumberSerde,\n EntityMetadata,\n EnumArrayFieldSerde,\n EnumFieldSerde,\n JsonSerde,\n KeySerde,\n PlainDateSerde,\n PlainDateTimeSerde,\n PlainTimeSerde,\n PolyComponent,\n PrimitiveSerde,\n SimpleFieldSerde,\n SuperstructSerde,\n ZodSerde,\n ZonedDateTimeSerde,\n polymorphicField,\n} from \"./symbols.ts\";\nimport { mapSimpleDbTypeToTypescriptType, q } from \"./utils.ts\";\n\nexport function generateMetadataFile(config: Config, dbMeta: DbMetadata, meta: EntityDbMetadata): Code {\n const { entity, createdAt, updatedAt, deletedAt } = meta;\n\n const fields = generateFields(config, dbMeta, meta, (name) => columnReference(dbMeta, meta, name));\n\n Object.values(fields).forEach((code) => code.asOneline());\n\n const maybeBaseType = meta.baseClassName ? `\"${meta.baseClassName}\"` : undefined;\n // We want to put inheritanceType: sti/cti onto base classes as well\n const maybeInheritanceType = meta.inheritanceType ? `inheritanceType: \"${meta.inheritanceType}\",` : \"\";\n const maybeStiColumn = meta.stiDiscriminatorField ? `stiDiscriminatorField: \"${meta.stiDiscriminatorField}\",` : \"\";\n const maybeStiValue = meta.stiDiscriminatorValue ? `stiDiscriminatorValue: ${meta.stiDiscriminatorValue},` : \"\";\n const maybeCtiAbstract = meta.abstract ? `ctiAbstract: ${meta.abstract},` : \"\";\n // Force subtype `timestampFields` to be `undefined` to ensure all runtime code is reading from the baseMeta values.\n // Force subtype `timestampFields` to be `undefined` to ensure all runtime code is reading from the baseMeta values.\n const maybeTimestampConfig = meta.baseClassName\n ? code`undefined`\n : code`\n {\n createdAt: ${q(createdAt?.fieldName)},\n updatedAt: ${q(updatedAt?.fieldName)},\n deletedAt: ${q(deletedAt?.fieldName)},\n }\n `;\n const maybeInsertionOrder = meta.nonDeferredFkOrder !== 0 ? `nonDeferredFkOrder: ${meta.nonDeferredFkOrder},` : ``;\n const uniqueBy = getUniqueBy(config, meta);\n const maybeUniqueBy = uniqueBy.length > 0 ? code`uniqueBy: ${JSON.stringify(uniqueBy)},` : code``;\n\n return code`\n export const ${entity.metaName}: ${EntityMetadata}<${entity.name}> = {\n cstr: ${entity.typeForMetadataFile},\n type: \"${entity.name}\",\n baseType: ${maybeBaseType}, ${maybeInheritanceType} ${maybeStiColumn} ${maybeStiValue} ${maybeCtiAbstract}\n idType: \"${config.idType ?? \"tagged-string\"}\",\n idDbType: \"${meta.primaryKey.columnType}\",\n tagName: \"${meta.tagName}\",\n tableName: \"${meta.tableName}\",\n supportsEmExecute: ${!meta.inheritanceType && meta.supportsEmExecute === true},\n fields: ${fields},\n columns: ${columnOwner(dbMeta, meta, \"id\").entity.metaName}Columns,\n allFields: {},\n orderBy: ${q(config.entities[meta.name]?.orderBy)},\n timestampFields: ${maybeTimestampConfig},\n config: ${entity.configConst},\n factory: ${imp(`new${entity.name}@./entities.ts`)},\n baseTypes: [],\n subTypes: [], ${maybeInsertionOrder} ${maybeUniqueBy}\n };\n\n (${entity.typeForMetadataFile} as any).metadata = ${entity.metaName};\n `;\n}\n\n/** Returns configured identities plus conservative database-backed unique identities. */\nfunction getUniqueBy(config: Config, meta: EntityDbMetadata): string[][] {\n const uniqueBy = config.entities[meta.name]?.uniqueBy ?? [];\n const seen = new Set<string>();\n return [...uniqueBy, ...(meta.uniqueConstraints ?? [])].filter((fields) => {\n const key = fields.join(\"\\u0000\");\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n\n/** Emits fields that bind the already-declared physical columns. */\nfunction generateFields(\n config: Config,\n dbMeta: DbMetadata,\n dbMetadata: EntityDbMetadata,\n columnRef: (name: string, codec?: Code, args?: Code) => Code,\n): Record<string, Code> {\n const fields: Record<string, Code> = {};\n\n fields[\"id\"] = code`\n {\n kind: \"primaryKey\",\n fieldName: \"id\",\n fieldIdName: undefined,\n required: true,\n serde: new ${SimpleFieldSerde}(\"id\", ${columnRef(\"id\", code`new ${KeySerde}(\"${dbMetadata.tagName}\", \"${dbMetadata.primaryKey.columnType}\")`, columnArgs(dbMetadata.primaryKey, dbMetadata, code`() => ${dbMetadata.entity.metaName}`))}),\n immutable: true,\n }\n `;\n\n dbMetadata.primitives.forEach((p) => {\n const { fieldName, derived, columnName, columnType, superstruct, zodSchema, customSerde, isArray } = p;\n const column = columnArgs(p, dbMetadata);\n let serde: Code;\n if (customSerde) {\n serde = isArray\n ? code`new ${CustomSerdeAdapter}( \"${columnType}[]\", ${customSerde}, true)`\n : code`new ${CustomSerdeAdapter}( \"${columnType}\", ${customSerde})`;\n } else if (superstruct) {\n serde = code`new ${SuperstructSerde}( ${superstruct})`;\n } else if (zodSchema) {\n serde = code`new ${ZodSerde}( ${zodSchema})`;\n } else if (columnType === \"numeric\" || columnType === \"decimal\") {\n serde = isArray ? code`new ${DecimalToNumberSerde}(true)` : code`new ${DecimalToNumberSerde}()`;\n } else if (columnType === \"jsonb\") {\n serde = code`new ${JsonSerde}()`;\n } else if (p.rawFieldType === \"bigint\") {\n serde = isArray ? code`new ${BigIntSerde}(true)` : code`new ${BigIntSerde}()`;\n } else {\n let serdeType: Import;\n if (columnType === \"date\") {\n serdeType = config.temporal ? PlainDateSerde : DateSerde;\n } else if (columnType === \"timestamp without time zone\") {\n serdeType = config.temporal ? PlainDateTimeSerde : DateSerde;\n } else if (columnType === \"timestamp with time zone\") {\n serdeType = config.temporal ? ZonedDateTimeSerde : DateSerde;\n } else if (columnType === \"time without time zone\") {\n serdeType = config.temporal ? PlainTimeSerde : PrimitiveSerde;\n } else {\n serdeType = PrimitiveSerde;\n }\n serde = isArray ? code`new ${serdeType}( \"${columnType}[]\", true)` : code`new ${serdeType}( \"${columnType}\")`;\n }\n const extras = columnType === \"citext\" ? code`citext: true,` : \"\";\n fields[fieldName] = code`\n {\n kind: \"primitive\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n derived: ${!derived ? false : `\"${derived}\"`},\n required: ${!derived && p.notNull},\n protected: ${p.protected},\n type: ${typeof p.rawFieldType === \"string\" ? `\"${p.rawFieldType}\"` : p.rawFieldType},\n serde: new ${SimpleFieldSerde}(\"${fieldName}\", ${columnRef(columnName, serde, column)}),\n immutable: false,\n ${p.lazy ? code`lazy: true,` : \"\"}\n ${extras}\n ${maybeDefault(p)}\n ${maybeSanitize(config, p)}\n }`;\n });\n\n // Treat native enums as primitives\n dbMetadata.pgEnums.forEach((p) => {\n const { columnName, fieldName, notNull, dbType } = p;\n fields[fieldName] = code`\n {\n kind: \"primitive\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n derived: false,\n required: ${notNull},\n protected: false,\n type: \"string\",\n serde: new ${SimpleFieldSerde}(\"${fieldName}\", ${columnRef(columnName, code`new ${PrimitiveSerde}(\"${dbType}\")`, columnArgs(p, dbMetadata))}),\n immutable: false,\n ${maybeDefault(p)}\n }`;\n });\n\n dbMetadata.enums.forEach((field) => {\n const { fieldName, enumDetailType, notNull, isArray, columnName, columnType, derived } = field;\n const serdeType = isArray ? EnumArrayFieldSerde : EnumFieldSerde;\n const columnTypeWithArray = `${columnType}${isArray ? \"[]\" : \"\"}`;\n fields[fieldName] = code`\n {\n kind: \"enum\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n required: ${notNull},\n derived: ${!derived ? false : `\"${derived}\"`},\n enumDetailType: ${enumDetailType},\n serde: new ${SimpleFieldSerde}(\"${fieldName}\", ${columnRef(columnName, code`new ${serdeType}(\"${columnTypeWithArray}\", ${enumDetailType})`, columnArgs(field, dbMetadata))}),\n immutable: false,\n ${maybeDefault(field)}\n }\n `;\n });\n\n dbMetadata.manyToOnes.forEach((m2o) => {\n const { fieldName, columnName, notNull, otherEntity, otherFieldName, derived, dbType } = m2o;\n const otherTagName = config.entities[otherEntity.name].tag;\n const physical = (dbMetadata.physicalMetadata ?? dbMetadata).manyToOnes.find(\n (field) => field.columnName === columnName,\n );\n const otherMetadata =\n physical?.otherEntity.name === otherEntity.name\n ? code`${columnRef(columnName)}.idMetadata!`\n : code`() => ${otherEntity.metaName}`;\n fields[fieldName] = code`\n {\n kind: \"m2o\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${fieldName}Id\",\n derived: ${!derived ? false : `\"${derived}\"`},\n required: ${notNull},\n otherMetadata: ${otherMetadata},\n otherFieldName: \"${otherFieldName}\",\n serde: new ${SimpleFieldSerde}(\"${fieldName}\", ${columnRef(columnName, code`new ${KeySerde}(\"${otherTagName}\", \"${dbType}\")`, columnArgs(m2o, dbMetadata, code`() => ${otherEntity.metaName}`))}),\n immutable: false,\n ${maybeDefault(m2o)}\n }\n `;\n });\n\n dbMetadata.oneToManys.forEach((o2m) => {\n const { fieldName, singularName, otherEntity, otherFieldName, otherColumnName } = o2m;\n fields[fieldName] = code`\n {\n kind: \"o2m\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${singularName}Ids\",\n required: false,\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n otherColumnName: \"${otherColumnName}\",\n serde: undefined,\n immutable: false,\n ${maybeOrderBy(o2m)}\n ${maybeSoftDeletes(o2m)}\n }\n `;\n });\n\n dbMetadata.largeOneToManys.forEach((o2m) => {\n const { fieldName, singularName, otherEntity, otherFieldName, otherColumnName } = o2m;\n fields[fieldName] = code`\n {\n kind: \"lo2m\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${singularName}Ids\",\n required: false,\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n otherColumnName: \"${otherColumnName}\",\n serde: undefined,\n immutable: false,\n }\n `;\n });\n\n dbMetadata.manyToManys.forEach((m2m) => {\n const { fieldName, singularName, otherEntity, otherFieldName, derived } = m2m;\n fields[fieldName] = code`\n {\n kind: \"m2m\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${singularName}Ids\",\n required: false,\n derived: ${derived === \"async\" ? `\"async\"` : derived === \"otherSide\" ? `\"otherSide\"` : \"false\"},\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n serde: undefined,\n immutable: false,\n joinTableName: \"${m2m.joinTableName}\",\n columnNames: [\"${m2m.columnName}\", \"${m2m.otherColumnName}\"],\n hasJoinTableId: ${m2m.hasJoinTableId},\n ${maybeSoftDeletes(m2m)}\n }\n `;\n });\n\n dbMetadata.manyToManyEnums.forEach((m2m) => {\n const { fieldName, enumDetailType } = m2m;\n fields[fieldName] = code`\n {\n kind: \"m2mEnum\",\n fieldName: \"${fieldName}\",\n fieldIdName: undefined,\n required: false,\n derived: false,\n enumDetailType: ${enumDetailType},\n serde: undefined,\n immutable: false,\n joinTableName: \"${m2m.joinTableName}\",\n columnNames: [\"${m2m.columnName}\", \"${m2m.otherColumnName}\"],\n hasJoinTableId: ${m2m.hasJoinTableId},\n }\n `;\n });\n\n dbMetadata.oneToOnes.forEach((o2o) => {\n const { fieldName, otherEntity, otherFieldName, otherColumnName } = o2o;\n fields[fieldName] = code`\n {\n kind: \"o2o\",\n fieldName: \"${fieldName}\",\n fieldIdName: \"${fieldName}Id\",\n required: false,\n otherMetadata: () => ${otherEntity.metaName},\n otherFieldName: \"${otherFieldName}\",\n otherColumnName: \"${otherColumnName}\",\n serde: undefined,\n immutable: false,\n }\n `;\n });\n\n dbMetadata.polymorphics.forEach((p) => {\n const { fieldName, notNull, components } = p;\n components.forEach((component) =>\n columnRef(\n component.columnName,\n code`new ${KeySerde}(\"${config.entities[component.otherEntity.name].tag}\", \"${dbMeta.entitiesByName[component.otherEntity.name].primaryKey.columnType}\")`,\n code`true, false, false, false, false, () => ${component.otherEntity.metaName}`,\n ),\n );\n fields[fieldName] = code`\n ${polymorphicField}(\"${fieldName}\", ${notNull}, [${components.map((component) => {\n const owner = columnOwner(dbMeta, dbMetadata, component.columnName);\n const physical = (owner.physicalMetadata ?? owner).polymorphics\n .flatMap((field) => field.components)\n .find((c) => c.columnName === component.columnName)!;\n const target =\n physical.otherEntity.name === component.otherEntity.name\n ? \"\"\n : code`, () => ${component.otherEntity.metaName}`;\n return code`new ${PolyComponent}(${columnRef(component.columnName)}, ${q(component.otherFieldName)}${target}),`;\n })}])\n `;\n });\n\n return fields;\n}\n\n/** Emits constructor arguments using codegen's existing column facts. */\nfunction columnArgs(\n column: Pick<PrimitiveField, \"columnNotNull\" | \"columnGenerated\"> & Partial<Pick<PrimitiveField, \"columnDefault\">>,\n meta: EntityDbMetadata,\n idMetadata?: Code,\n): Code {\n const insertOptional = column === meta.createdAt || column === meta.updatedAt;\n return code`${!column.columnNotNull}, ${column.columnDefault != null && !column.columnGenerated}, ${column.columnGenerated}, ${insertOptional}, true, ${idMetadata ?? \"undefined\"}`;\n}\n\n/** Declares all physical codecs before any domain metadata; ID targets remain lazy. */\nexport function generateColumnDeclarations(config: Config, dbMeta: DbMetadata, meta: EntityDbMetadata): Code {\n if (meta.inheritanceType === \"sti\" && meta.baseClassName) return code``;\n const columns: Record<string, Code> = {};\n generateFields(config, dbMeta, meta.physicalMetadata ?? meta, (name, codec, args) => {\n if (codec) columns[name] = code`new ${Column}(${q(name)}, ${args}, ${codec})`.asOneline();\n return code`${meta.entity.metaName}Columns[${q(name)}]`;\n });\n return code`const ${meta.entity.metaName}Columns = ${columns} satisfies ${ColumnDescriptors};`;\n}\n\n/** Locates a column's physical table without copying inherited columns into subtype tables. */\nfunction columnOwner(dbMeta: DbMetadata, meta: EntityDbMetadata, name: string): EntityDbMetadata {\n if (meta.inheritanceType === \"sti\" && meta.baseClassName) {\n return columnOwner(dbMeta, dbMeta.entitiesByName[meta.baseClassName], name);\n }\n const physical = meta.physicalMetadata ?? meta;\n if (\n name === \"id\" ||\n [\n ...physical.primitives,\n ...physical.enums,\n ...physical.pgEnums,\n ...physical.manyToOnes,\n ...physical.polymorphics.flatMap((field) => field.components),\n ].some((field) => field.columnName === name)\n )\n return meta;\n if (meta.baseClassName) return columnOwner(dbMeta, dbMeta.entitiesByName[meta.baseClassName], name);\n throw new Error(`No physical column ${meta.name}.${name}`);\n}\n\n/** Emits a direct reference to the single physical descriptor. */\nfunction columnReference(dbMeta: DbMetadata, meta: EntityDbMetadata, name: string): Code {\n return code`${columnOwner(dbMeta, meta, name).entity.metaName}Columns[${q(name)}]`;\n}\n\nfunction maybeDefault(f: { hasConfigDefault: boolean; columnDefault?: number | boolean | string | null }): Code | \"\" {\n return f.hasConfigDefault ? code`default: \"config\",` : f.columnDefault != null ? code`default: \"schema\",` : \"\";\n}\n\nfunction maybeOrderBy(f: OneToManyField): Code | \"\" {\n return f.orderBy ? code`orderBy: { field: \"${f.orderBy.field}\", direction: \"${f.orderBy.direction}\" },` : \"\";\n}\n\n/** Emits the `softDeletes` config, i.e. `softDeletes: \"include\",`, for relations that opt out of hiding soft-deletes. */\nfunction maybeSoftDeletes(f: { softDeletes: \"include\" | \"exclude\" | undefined }): Code | \"\" {\n return f.softDeletes ? code`softDeletes: \"${f.softDeletes}\",` : \"\";\n}\n\n/** We sanitize/cleanStringValue all varchars, unless opted out by the column default/arrays/custom serdes. */\nfunction maybeSanitize(\n config: Config,\n f: { columnType: DatabaseColumnType; columnDefault?: any; isArray: boolean; customSerde: any },\n): Code | \"\" {\n // Only strings need to maybe turn off their cleanStringValue sanitization, if the default=\"\" or its an array\n return isString(config, f.columnType) && (f.columnDefault === \"''\" || f.isArray || f.customSerde)\n ? code`sanitize: false,`\n : \"\";\n}\n\nfunction isString(config: Config, columnType: DatabaseColumnType): boolean {\n return mapSimpleDbTypeToTypescriptType(config, columnType) === \"string\";\n}\n"],"mappings":";;;;;;AAmCA,SAAgB,qBAAqB,QAAgB,QAAoB,MAA8B;CACrG,MAAM,EAAE,QAAQ,WAAW,WAAW,cAAc;CAEpD,MAAM,SAAS,eAAe,QAAQ,QAAQ,OAAO,SAAS,gBAAgB,QAAQ,MAAM,IAAI,CAAC;CAEjG,OAAO,OAAO,MAAM,CAAC,CAAC,SAAS,SAAS,KAAK,UAAU,CAAC;CAExD,MAAM,gBAAgB,KAAK,gBAAgB,IAAI,KAAK,cAAc,KAAK,KAAA;CAEvE,MAAM,uBAAuB,KAAK,kBAAkB,qBAAqB,KAAK,gBAAgB,MAAM;CACpG,MAAM,iBAAiB,KAAK,wBAAwB,2BAA2B,KAAK,sBAAsB,MAAM;CAChH,MAAM,gBAAgB,KAAK,wBAAwB,0BAA0B,KAAK,sBAAsB,KAAK;CAC7G,MAAM,mBAAmB,KAAK,WAAW,gBAAgB,KAAK,SAAS,KAAK;CAG5E,MAAM,uBAAuB,KAAK,gBAC9B,IAAI,cACJ,IAAI;;mBAES,EAAE,WAAW,SAAS,EAAE;mBACxB,EAAE,WAAW,SAAS,EAAE;mBACxB,EAAE,WAAW,SAAS,EAAE;;;CAGzC,MAAM,sBAAsB,KAAK,uBAAuB,IAAI,uBAAuB,KAAK,mBAAmB,KAAK;CAChH,MAAM,WAAW,YAAY,QAAQ,IAAI;CACzC,MAAM,gBAAgB,SAAS,SAAS,IAAI,IAAI,aAAa,KAAK,UAAU,QAAQ,EAAE,KAAK,IAAI;CAE/F,OAAO,IAAI;mBACM,OAAO,SAAS,IAAI,eAAe,GAAG,OAAO,KAAK;cACvD,OAAO,oBAAoB;eAC1B,OAAO,KAAK;kBACT,cAAc,IAAI,qBAAqB,GAAG,eAAe,GAAG,cAAc,GAAG,iB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CAC1F,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,YAAY,MAAM;AAClE;;AAGA,SAAS,cACP,QACA,GACW;CAEX,OAAO,SAAS,QAAQ,EAAE,UAAU,MAAM,EAAE,kBAAkB,QAAQ,EAAE,WAAW,EAAE,eACjF,IAAI,qBACJ;AACN;AAEA,SAAS,SAAS,QAAgB,YAAyC;CACzE,OAAO,gCAAgC,QAAQ,UAAU,MAAM;AACjE"}
@@ -3,8 +3,35 @@ const require_utils = require("./utils.cjs");
3
3
  require("./config.cjs");
4
4
  const require_EntityDbMetadata = require("./EntityDbMetadata.cjs");
5
5
  //#region src/inheritance.ts
6
+ /** Preserves physical storage metadata, then applies domain inheritance specialization. */
6
7
  function applyInheritanceUpdates(config, db) {
7
8
  const { entities, entitiesByName } = db;
9
+ for (const meta of entities) {
10
+ meta.physicalMetadata = {
11
+ ...meta,
12
+ name: meta.name,
13
+ primitives: meta.primitives.map((field) => ({ ...field })),
14
+ enums: meta.enums.map((field) => ({ ...field })),
15
+ pgEnums: meta.pgEnums.map((field) => ({ ...field })),
16
+ manyToOnes: meta.manyToOnes.map((field) => ({ ...field })),
17
+ oneToManys: meta.oneToManys.map((field) => ({ ...field })),
18
+ largeOneToManys: meta.largeOneToManys.map((field) => ({ ...field })),
19
+ oneToOnes: meta.oneToOnes.map((field) => ({ ...field })),
20
+ manyToManys: meta.manyToManys.map((field) => ({ ...field })),
21
+ largeManyToManys: meta.largeManyToManys.map((field) => ({ ...field })),
22
+ polymorphics: meta.polymorphics.map((field) => ({
23
+ ...field,
24
+ components: field.components.map((component) => ({ ...component }))
25
+ })),
26
+ nonDeferredFks: meta.nonDeferredFks,
27
+ nonDeferredManyToManyFks: meta.nonDeferredManyToManyFks
28
+ };
29
+ for (const timestamp of [
30
+ "createdAt",
31
+ "updatedAt",
32
+ "deletedAt"
33
+ ]) meta.physicalMetadata[timestamp] = meta.physicalMetadata.primitives.find((field) => field.fieldName === meta[timestamp]?.fieldName);
34
+ }
8
35
  setClassTableInheritance(entities, entitiesByName);
9
36
  expandSingleTableInheritance(config, entitiesByName, entities);
10
37
  rewriteSingleTableForeignKeys(config, entities);
@@ -101,6 +128,7 @@ function expandSingleTableInheritance(config, entitiesByName, entities) {
101
128
  name: subTypeName,
102
129
  entity: require_EntityDbMetadata.makeEntity(subTypeName),
103
130
  tableName: entity.tableName,
131
+ physicalMetadata: entity.physicalMetadata,
104
132
  primaryKey: entity.primaryKey,
105
133
  primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
106
134
  enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
@@ -1 +1 @@
1
- {"version":3,"file":"inheritance.cjs","names":["makeEntity","fail"],"sources":["../src/inheritance.ts"],"sourcesContent":["import { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type ManyToManyField,\n type ManyToOneField,\n type PolymorphicFieldComponent,\n canonicalizeOtherEntities,\n makeEntity,\n} from \"./EntityDbMetadata.ts\";\nimport { fail } from \"./utils.ts\";\n\nexport function applyInheritanceUpdates(config: Config, db: DbMetadata): void {\n const { entities, entitiesByName } = db;\n setClassTableInheritance(entities, entitiesByName);\n expandSingleTableInheritance(config, entitiesByName, entities);\n rewriteSingleTableForeignKeys(config, entities);\n setupSubTypeSpecialization(config, entities);\n // Now that all relations (incl. specialized ones) exist, collapse the duplicate `otherEntity` objects\n canonicalizeOtherEntities(db);\n}\n\n/**\n * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.\n *\n * I.e. `SmallPublishers.group: SmallPublisherGroup`.\n *\n * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,\n * once for the base and once for the child, which is unusual, but gets the types generated\n * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating\n * `meta.allFields`.\n */\nfunction setupSubTypeSpecialization(config: Config, entities: EntityDbMetadata[]): void {\n for (const entity of entities) {\n if (entity.baseType) {\n const entityConfig = config.entities[entity.name];\n const baseConfig = config.entities[entity.baseType.name];\n // Look through the base's m2os & o2ms, looking for a config specialization\n for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {\n const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};\n const subType =\n entityConfig?.relations?.[rel.fieldName]?.subType ??\n baseConfig?.relations?.[rel.fieldName]?.subType ??\n // Probe the otherFieldName for a `subType: \"self\"` on self-referential relations in STI tables\n baseConfig?.relations?.[rel.otherFieldName]?.subType ??\n // if we are only marking the relation as required and not specifying a subtype, then use the original type\n (notNull ? rel.otherEntity.name : undefined);\n\n if (!subType) {\n // continue...\n } else if (subType === \"self\" && rel.kind === \"m2o\") {\n // Specialize `TaskNew.copiedFrom: TaskNew` & `TaskOld.copiedFrom: TaskOld`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (subType === \"self\" && rel.kind === \"o2m\") {\n // Specialize `TaskNew.copiedTo: TaskNew[]` & `TaskOld.copiedTo: TaskOld[]`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (rel.kind === \"m2o\") {\n // Specialize `SmallPublisher.group: SmallPublisherGroup`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n } else if (rel.kind === \"o2m\") {\n // Specialize `SmallPublisherGroup.publishers: SmallPublisher`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n }\n }\n\n // Look through the base's primitives looking for a config specialization\n for (const field of entity.baseType?.primitives ?? []) {\n // the only specialization a primitive can have is nullability\n const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};\n if (notNull) {\n entity.primitives.push({ ...field, notNull });\n }\n }\n }\n }\n}\n\n/**\n * Ensure CTI base types have their inheritanceType set.\n *\n * (We automatically set `inheritanceType` for STI tables when we see their config\n * setup, see `expandSingleTableInheritance`.)\n */\nfunction setClassTableInheritance(\n entities: EntityDbMetadata[],\n entitiesByName: Record<string, EntityDbMetadata>,\n): void {\n const ctiBaseNames: string[] = [];\n for (const entity of entities) {\n if (entity.baseClassName) {\n ctiBaseNames.push(entity.baseClassName);\n const base = entitiesByName[entity.baseClassName];\n entity.baseType = base;\n base.subTypes.push(entity);\n }\n }\n for (const entity of entities) {\n if (ctiBaseNames.includes(entity.name)) entity.inheritanceType = \"cti\";\n }\n}\n\n/** Expands STI tables into multiple entities, so they get separate `SubTypeCodegen.ts` & `SubType.ts` files. */\nfunction expandSingleTableInheritance(\n config: Config,\n entitiesByName: Record<string, EntityDbMetadata>,\n entities: EntityDbMetadata[],\n): void {\n for (const entity of entities) {\n const [fieldName, stiField] =\n Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];\n if (fieldName && stiField && stiField.stiDiscriminator) {\n entity.inheritanceType = \"sti\";\n\n // Ensure we have an enum field so that we can bake the STI discriminators into the metadata.ts file\n const enumField =\n entity.enums.find((e) => e.fieldName === fieldName) ??\n fail(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);\n entity.stiDiscriminatorField = enumField.fieldName;\n\n // Find the available discriminators/subtypes, i.e. NEW => NewTask, OLD => OldTask, etc.\n const subTypes = Object.entries(stiField.stiDiscriminator);\n\n const allFields = [\n ...Object.entries(config.entities[entity.name]?.fields ?? {}),\n ...Object.entries(config.entities[entity.name]?.relations ?? {}),\n ];\n\n // Make sure there aren't any typos in `stiType`s\n const availableCodes = subTypes.map(([code]) => code);\n const availableNames = subTypes.map(([, name]) => name);\n const available = [...availableCodes, ...availableNames];\n allFields.filter(([name, f]) => {\n if (f.stiType && !available.includes(f.stiType)) {\n fail(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(\", \")}`);\n }\n });\n\n // Now split each subType out into its out entity\n for (const [enumCode, subTypeName] of subTypes) {\n // Find all the base entity's fields that belong to us\n const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);\n const subTypeFieldNames = subTypeFields.map(([name]) => name);\n\n // Make fields as required\n function maybeRequired<T extends { notNull: boolean; fieldName: string }>(field: T): T {\n const config = subTypeFields.find(([name]) => name === field.fieldName)?.[1]!;\n if (config.notNull) field.notNull = true;\n return field;\n }\n\n // Synthesize an entity for this STI sub-entity\n const subEntity: EntityDbMetadata = {\n name: subTypeName,\n entity: makeEntity(subTypeName),\n tableName: entity.tableName,\n primaryKey: entity.primaryKey,\n primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n tagName: entity.tagName,\n createdAt: undefined,\n updatedAt: undefined,\n deletedAt: undefined,\n baseClassName: entity.name,\n baseType: entity,\n subTypes: [],\n inheritanceType: \"sti\",\n stiDiscriminatorValue: (\n enumField.enumRows.find((r) => r.code === enumCode) ??\n fail(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)\n ).id,\n abstract: false,\n nonDeferredFkOrder: entity.nonDeferredFkOrder,\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 get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n },\n };\n\n // Now strip all the subclass fields from the base class\n entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.subTypes.push(subEntity);\n\n entities.push(subEntity);\n entitiesByName[subEntity.name] = subEntity;\n }\n }\n }\n}\n\ntype StiEntityMap = Map<string, { base: EntityDbMetadata; subTypes: EntityDbMetadata[] }>;\nlet stiEntities: StiEntityMap;\n\nexport function getStiEntities(entities: EntityDbMetadata[]): StiEntityMap {\n if (stiEntities) return stiEntities;\n stiEntities = new Map();\n for (const entity of entities) {\n if (entity.inheritanceType === \"sti\" && entity.stiDiscriminatorField) {\n const base = entity;\n const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);\n stiEntities.set(entity.name, { base, subTypes });\n // Allow looking up by subType name\n for (const subType of subTypes) {\n stiEntities.set(subType.name, { base, subTypes: [] });\n }\n }\n }\n return stiEntities;\n}\n\n/** Finds FKs pointing to the base table and, if configured, rewrites them to point to the sub-tables. */\nfunction rewriteSingleTableForeignKeys(config: Config, entities: EntityDbMetadata[]): void {\n // See if we even have any STI tables\n const stiEntities = getStiEntities(entities);\n if (stiEntities.size === 0) return;\n // Scan for other entities/relations that point to the STI table\n for (const entity of entities) {\n // m2os -- Look for `entity.task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const m2o of entity.manyToOnes) {\n const target = stiEntities.get(m2o.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n m2o.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n // polys -- Look for `entity.parent_task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const poly of entity.polymorphics) {\n for (const comp of poly.components) {\n const target = stiEntities.get(comp.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n comp.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n }\n // o2ms -- Look for `entity.tasks` collections loading `task.entity_id`, but entity has been pushed down to `TaskOld`\n for (const o2m of entity.oneToManys) {\n const target = stiEntities.get(o2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) &&\n st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName),\n );\n if (otherField) {\n o2m.otherEntity = otherField.entity;\n }\n }\n }\n // m2ms -- Look for `entity.tasks` collections loading m2m rows, but `entity` has been pushed down to `TaskOld`\n for (const m2m of entity.manyToManys) {\n const target = stiEntities.get(m2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) &&\n st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName),\n );\n if (otherField) {\n m2m.otherEntity = otherField.entity;\n }\n }\n }\n }\n}\n"],"mappings":";;;;;AAYA,SAAgB,wBAAwB,QAAgB,IAAsB;CAC5E,MAAM,EAAE,UAAU,mBAAmB;CACrC,yBAAyB,UAAU,cAAc;CACjD,6BAA6B,QAAQ,gBAAgB,QAAQ;CAC7D,8BAA8B,QAAQ,QAAQ;CAC9C,2BAA2B,QAAQ,QAAQ;CAE3C,yBAAA,0BAA0B,EAAE;AAC9B;;;;;;;;;;;AAYA,SAAS,2BAA2B,QAAgB,UAAoC;CACtF,KAAK,MAAM,UAAU,UACnB,IAAI,OAAO,UAAU;EACnB,MAAM,eAAe,OAAO,SAAS,OAAO;EAC5C,MAAM,aAAa,OAAO,SAAS,OAAO,SAAS;EAEnD,KAAK,MAAM,OAAO,CAAC,GAAG,OAAO,SAAS,YAAY,GAAG,OAAO,SAAS,UAAU,GAAG;GAChF,MAAM,EAAE,YAAY,cAAc,YAAY,IAAI,cAAc,CAAC;GACjE,MAAM,UACJ,cAAc,YAAY,IAAI,UAAU,EAAE,WAC1C,YAAY,YAAY,IAAI,UAAU,EAAE,WAExC,YAAY,YAAY,IAAI,eAAe,EAAE,YAE5C,UAAU,IAAI,YAAY,OAAO,KAAA;GAEpC,IAAI,CAAC,SAAS,C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O;GAEjC,MAAM,UAAU,QAAQ,OAAO,SAAS,KAAK,EAAE,YAAY,KAAK,eAAe,EAAE;GACjF,IAAI,UAAU,SAAS;IACrB,MAAM,EAAE,aAAa;IACrB,KAAK,eACH,SAAS,MAAM,MAAM,EAAE,SAAS,OAAO,KACvCA,cAAAA,KAAK,4BAA4B,QAAQ,OAAO,SAAS,KAAK,MAAM,EAAE,IAAI,GAAG,EAAA,CAC7E;GACJ;EACF;EAGF,KAAK,MAAM,OAAO,OAAO,YAAY;GACnC,MAAM,SAAS,YAAY,IAAI,IAAI,YAAY,IAAI;GACnD,IAAI,UAAU,OAAO,KAAK,oBAAoB,OAAO;IAEnD,MAAM,aAAa,OAAO,SAAS,MAChC,OACC,CAAC,OAAO,KAAK,WAAW,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,KACtE,GAAG,WAAW,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,CAChE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;EAEA,KAAK,MAAM,OAAO,OAAO,aAAa;GACpC,MAAM,SAAS,YAAY,IAAI,IAAI,YAAY,IAAI;GACnD,IAAI,UAAU,OAAO,KAAK,oBAAoB,OAAO;IAEnD,MAAM,aAAa,OAAO,SAAS,MAChC,OACC,CAAC,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,KACvE,GAAG,YAAY,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,CACjE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;CACF;AACF"}
1
+ {"version":3,"file":"inheritance.cjs","names":["makeEntity","fail"],"sources":["../src/inheritance.ts"],"sourcesContent":["import { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type ManyToManyField,\n type ManyToOneField,\n type PolymorphicFieldComponent,\n canonicalizeOtherEntities,\n makeEntity,\n} from \"./EntityDbMetadata.ts\";\nimport { fail } from \"./utils.ts\";\n\n/** Preserves physical storage metadata, then applies domain inheritance specialization. */\nexport function applyInheritanceUpdates(config: Config, db: DbMetadata): void {\n const { entities, entitiesByName } = db;\n // Preserve storage domains before STI moves fields or rewrites relationship targets.\n for (const meta of entities) {\n meta.physicalMetadata = {\n ...meta,\n name: meta.name,\n primitives: meta.primitives.map((field) => ({ ...field })),\n enums: meta.enums.map((field) => ({ ...field })),\n pgEnums: meta.pgEnums.map((field) => ({ ...field })),\n manyToOnes: meta.manyToOnes.map((field) => ({ ...field })),\n oneToManys: meta.oneToManys.map((field) => ({ ...field })),\n largeOneToManys: meta.largeOneToManys.map((field) => ({ ...field })),\n oneToOnes: meta.oneToOnes.map((field) => ({ ...field })),\n manyToManys: meta.manyToManys.map((field) => ({ ...field })),\n largeManyToManys: meta.largeManyToManys.map((field) => ({ ...field })),\n polymorphics: meta.polymorphics.map((field) => ({\n ...field,\n components: field.components.map((component) => ({ ...component })),\n })),\n nonDeferredFks: meta.nonDeferredFks,\n nonDeferredManyToManyFks: meta.nonDeferredManyToManyFks,\n };\n for (const timestamp of [\"createdAt\", \"updatedAt\", \"deletedAt\"] as const) {\n meta.physicalMetadata[timestamp] = meta.physicalMetadata.primitives.find(\n (field) => field.fieldName === meta[timestamp]?.fieldName,\n );\n }\n }\n setClassTableInheritance(entities, entitiesByName);\n expandSingleTableInheritance(config, entitiesByName, entities);\n rewriteSingleTableForeignKeys(config, entities);\n setupSubTypeSpecialization(config, entities);\n // Now that all relations (incl. specialized ones) exist, collapse the duplicate `otherEntity` objects\n canonicalizeOtherEntities(db);\n}\n\n/**\n * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.\n *\n * I.e. `SmallPublishers.group: SmallPublisherGroup`.\n *\n * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,\n * once for the base and once for the child, which is unusual, but gets the types generated\n * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating\n * `meta.allFields`.\n */\nfunction setupSubTypeSpecialization(config: Config, entities: EntityDbMetadata[]): void {\n for (const entity of entities) {\n if (entity.baseType) {\n const entityConfig = config.entities[entity.name];\n const baseConfig = config.entities[entity.baseType.name];\n // Look through the base's m2os & o2ms, looking for a config specialization\n for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {\n const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};\n const subType =\n entityConfig?.relations?.[rel.fieldName]?.subType ??\n baseConfig?.relations?.[rel.fieldName]?.subType ??\n // Probe the otherFieldName for a `subType: \"self\"` on self-referential relations in STI tables\n baseConfig?.relations?.[rel.otherFieldName]?.subType ??\n // if we are only marking the relation as required and not specifying a subtype, then use the original type\n (notNull ? rel.otherEntity.name : undefined);\n\n if (!subType) {\n // continue...\n } else if (subType === \"self\" && rel.kind === \"m2o\") {\n // Specialize `TaskNew.copiedFrom: TaskNew` & `TaskOld.copiedFrom: TaskOld`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (subType === \"self\" && rel.kind === \"o2m\") {\n // Specialize `TaskNew.copiedTo: TaskNew[]` & `TaskOld.copiedTo: TaskOld[]`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (rel.kind === \"m2o\") {\n // Specialize `SmallPublisher.group: SmallPublisherGroup`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n } else if (rel.kind === \"o2m\") {\n // Specialize `SmallPublisherGroup.publishers: SmallPublisher`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n }\n }\n\n // Look through the base's primitives looking for a config specialization\n for (const field of entity.baseType?.primitives ?? []) {\n // the only specialization a primitive can have is nullability\n const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};\n if (notNull) {\n entity.primitives.push({ ...field, notNull });\n }\n }\n }\n }\n}\n\n/**\n * Ensure CTI base types have their inheritanceType set.\n *\n * (We automatically set `inheritanceType` for STI tables when we see their config\n * setup, see `expandSingleTableInheritance`.)\n */\nfunction setClassTableInheritance(\n entities: EntityDbMetadata[],\n entitiesByName: Record<string, EntityDbMetadata>,\n): void {\n const ctiBaseNames: string[] = [];\n for (const entity of entities) {\n if (entity.baseClassName) {\n ctiBaseNames.push(entity.baseClassName);\n const base = entitiesByName[entity.baseClassName];\n entity.baseType = base;\n base.subTypes.push(entity);\n }\n }\n for (const entity of entities) {\n if (ctiBaseNames.includes(entity.name)) entity.inheritanceType = \"cti\";\n }\n}\n\n/** Expands STI tables into multiple entities, so they get separate `SubTypeCodegen.ts` & `SubType.ts` files. */\nfunction expandSingleTableInheritance(\n config: Config,\n entitiesByName: Record<string, EntityDbMetadata>,\n entities: EntityDbMetadata[],\n): void {\n for (const entity of entities) {\n const [fieldName, stiField] =\n Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];\n if (fieldName && stiField && stiField.stiDiscriminator) {\n entity.inheritanceType = \"sti\";\n\n // Ensure we have an enum field so that we can bake the STI discriminators into the metadata.ts file\n const enumField =\n entity.enums.find((e) => e.fieldName === fieldName) ??\n fail(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);\n entity.stiDiscriminatorField = enumField.fieldName;\n\n // Find the available discriminators/subtypes, i.e. NEW => NewTask, OLD => OldTask, etc.\n const subTypes = Object.entries(stiField.stiDiscriminator);\n\n const allFields = [\n ...Object.entries(config.entities[entity.name]?.fields ?? {}),\n ...Object.entries(config.entities[entity.name]?.relations ?? {}),\n ];\n\n // Make sure there aren't any typos in `stiType`s\n const availableCodes = subTypes.map(([code]) => code);\n const availableNames = subTypes.map(([, name]) => name);\n const available = [...availableCodes, ...availableNames];\n allFields.filter(([name, f]) => {\n if (f.stiType && !available.includes(f.stiType)) {\n fail(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(\", \")}`);\n }\n });\n\n // Now split each subType out into its out entity\n for (const [enumCode, subTypeName] of subTypes) {\n // Find all the base entity's fields that belong to us\n const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);\n const subTypeFieldNames = subTypeFields.map(([name]) => name);\n\n // Make fields as required\n function maybeRequired<T extends { notNull: boolean; fieldName: string }>(field: T): T {\n const config = subTypeFields.find(([name]) => name === field.fieldName)?.[1]!;\n if (config.notNull) field.notNull = true;\n return field;\n }\n\n // Synthesize an entity for this STI sub-entity\n const subEntity: EntityDbMetadata = {\n name: subTypeName,\n entity: makeEntity(subTypeName),\n tableName: entity.tableName,\n physicalMetadata: entity.physicalMetadata,\n primaryKey: entity.primaryKey,\n primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n tagName: entity.tagName,\n createdAt: undefined,\n updatedAt: undefined,\n deletedAt: undefined,\n baseClassName: entity.name,\n baseType: entity,\n subTypes: [],\n inheritanceType: \"sti\",\n stiDiscriminatorValue: (\n enumField.enumRows.find((r) => r.code === enumCode) ??\n fail(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)\n ).id,\n abstract: false,\n nonDeferredFkOrder: entity.nonDeferredFkOrder,\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 get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n },\n };\n\n // Now strip all the subclass fields from the base class\n entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.subTypes.push(subEntity);\n\n entities.push(subEntity);\n entitiesByName[subEntity.name] = subEntity;\n }\n }\n }\n}\n\ntype StiEntityMap = Map<string, { base: EntityDbMetadata; subTypes: EntityDbMetadata[] }>;\nlet stiEntities: StiEntityMap;\n\nexport function getStiEntities(entities: EntityDbMetadata[]): StiEntityMap {\n if (stiEntities) return stiEntities;\n stiEntities = new Map();\n for (const entity of entities) {\n if (entity.inheritanceType === \"sti\" && entity.stiDiscriminatorField) {\n const base = entity;\n const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);\n stiEntities.set(entity.name, { base, subTypes });\n // Allow looking up by subType name\n for (const subType of subTypes) {\n stiEntities.set(subType.name, { base, subTypes: [] });\n }\n }\n }\n return stiEntities;\n}\n\n/** Finds FKs pointing to the base table and, if configured, rewrites them to point to the sub-tables. */\nfunction rewriteSingleTableForeignKeys(config: Config, entities: EntityDbMetadata[]): void {\n // See if we even have any STI tables\n const stiEntities = getStiEntities(entities);\n if (stiEntities.size === 0) return;\n // Scan for other entities/relations that point to the STI table\n for (const entity of entities) {\n // m2os -- Look for `entity.task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const m2o of entity.manyToOnes) {\n const target = stiEntities.get(m2o.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n m2o.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n // polys -- Look for `entity.parent_task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const poly of entity.polymorphics) {\n for (const comp of poly.components) {\n const target = stiEntities.get(comp.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n comp.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n }\n // o2ms -- Look for `entity.tasks` collections loading `task.entity_id`, but entity has been pushed down to `TaskOld`\n for (const o2m of entity.oneToManys) {\n const target = stiEntities.get(o2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) &&\n st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName),\n );\n if (otherField) {\n o2m.otherEntity = otherField.entity;\n }\n }\n }\n // m2ms -- Look for `entity.tasks` collections loading m2m rows, but `entity` has been pushed down to `TaskOld`\n for (const m2m of entity.manyToManys) {\n const target = stiEntities.get(m2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) &&\n st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName),\n );\n if (otherField) {\n m2m.otherEntity = otherField.entity;\n }\n }\n }\n }\n}\n"],"mappings":";;;;;;AAaA,SAAgB,wBAAwB,QAAgB,IAAsB;CAC5E,MAAM,EAAE,UAAU,mBAAmB;CAErC,KAAK,MAAM,QAAQ,UAAU;EAC3B,KAAK,mBAAmB;GACtB,GAAG;GACH,MAAM,KAAK;GACX,YAAY,KAAK,WAAW,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACzD,OAAO,KAAK,MAAM,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GAC/C,SAAS,KAAK,QAAQ,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACnD,YAAY,KAAK,WAAW,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACzD,YAAY,KAAK,WAAW,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACzD,iBAAiB,KAAK,gBAAgB,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACnE,WAAW,KAAK,UAAU,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACvD,aAAa,KAAK,YAAY,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GAC3D,kBAAkB,KAAK,i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AAK,4BAA4B,QAAQ,OAAO,SAAS,KAAK,MAAM,EAAE,IAAI,GAAG,EAAA,CAC7E;GACJ;EACF;EAGF,KAAK,MAAM,OAAO,OAAO,YAAY;GACnC,MAAM,SAAS,YAAY,IAAI,IAAI,YAAY,IAAI;GACnD,IAAI,UAAU,OAAO,KAAK,oBAAoB,OAAO;IAEnD,MAAM,aAAa,OAAO,SAAS,MAChC,OACC,CAAC,OAAO,KAAK,WAAW,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,KACtE,GAAG,WAAW,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,CAChE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;EAEA,KAAK,MAAM,OAAO,OAAO,aAAa;GACpC,MAAM,SAAS,YAAY,IAAI,IAAI,YAAY,IAAI;GACnD,IAAI,UAAU,OAAO,KAAK,oBAAoB,OAAO;IAEnD,MAAM,aAAa,OAAO,SAAS,MAChC,OACC,CAAC,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,KACvE,GAAG,YAAY,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,CACjE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;CACF;AACF"}
@@ -1,6 +1,7 @@
1
1
  import { Config } from "./config.cjs";
2
2
  import { DbMetadata, EntityDbMetadata } from "./EntityDbMetadata.cjs";
3
3
  //#region src/inheritance.d.ts
4
+ /** Preserves physical storage metadata, then applies domain inheritance specialization. */
4
5
  declare function applyInheritanceUpdates(config: Config, db: DbMetadata): void;
5
6
  type StiEntityMap = Map<string, {
6
7
  base: EntityDbMetadata;
@@ -1 +1 @@
1
- {"version":3,"file":"inheritance.d.cts","names":[],"sources":["../src/inheritance.ts"],"mappings":";;;iBAYgB,wBAAwB,QAAQ,QAAQ,IAAI;KAyMvD,eAAe;EAAc,MAAM;EAAkB,UAAU;;iBAGpD,eAAe,UAAU,qBAAqB"}
1
+ {"version":3,"file":"inheritance.d.cts","names":[],"sources":["../src/inheritance.ts"],"mappings":";;;;iBAagB,wBAAwB,QAAQ,QAAQ,IAAI;KAqOvD,eAAe;EAAc,MAAM;EAAkB,UAAU;;iBAGpD,eAAe,UAAU,qBAAqB"}
@@ -1,6 +1,7 @@
1
1
  import { Config } from "./config.mjs";
2
2
  import { DbMetadata, EntityDbMetadata } from "./EntityDbMetadata.mjs";
3
3
  //#region src/inheritance.d.ts
4
+ /** Preserves physical storage metadata, then applies domain inheritance specialization. */
4
5
  declare function applyInheritanceUpdates(config: Config, db: DbMetadata): void;
5
6
  type StiEntityMap = Map<string, {
6
7
  base: EntityDbMetadata;
@@ -1 +1 @@
1
- {"version":3,"file":"inheritance.d.mts","names":[],"sources":["../src/inheritance.ts"],"mappings":";;;iBAYgB,wBAAwB,QAAQ,QAAQ,IAAI;KAyMvD,eAAe;EAAc,MAAM;EAAkB,UAAU;;iBAGpD,eAAe,UAAU,qBAAqB"}
1
+ {"version":3,"file":"inheritance.d.mts","names":[],"sources":["../src/inheritance.ts"],"mappings":";;;;iBAagB,wBAAwB,QAAQ,QAAQ,IAAI;KAqOvD,eAAe;EAAc,MAAM;EAAkB,UAAU;;iBAGpD,eAAe,UAAU,qBAAqB"}
@@ -2,8 +2,35 @@ import { fail } from "./utils.js";
2
2
  import "./config.js";
3
3
  import { canonicalizeOtherEntities, makeEntity } from "./EntityDbMetadata.js";
4
4
  //#region src/inheritance.ts
5
+ /** Preserves physical storage metadata, then applies domain inheritance specialization. */
5
6
  function applyInheritanceUpdates(config, db) {
6
7
  const { entities, entitiesByName } = db;
8
+ for (const meta of entities) {
9
+ meta.physicalMetadata = {
10
+ ...meta,
11
+ name: meta.name,
12
+ primitives: meta.primitives.map((field) => ({ ...field })),
13
+ enums: meta.enums.map((field) => ({ ...field })),
14
+ pgEnums: meta.pgEnums.map((field) => ({ ...field })),
15
+ manyToOnes: meta.manyToOnes.map((field) => ({ ...field })),
16
+ oneToManys: meta.oneToManys.map((field) => ({ ...field })),
17
+ largeOneToManys: meta.largeOneToManys.map((field) => ({ ...field })),
18
+ oneToOnes: meta.oneToOnes.map((field) => ({ ...field })),
19
+ manyToManys: meta.manyToManys.map((field) => ({ ...field })),
20
+ largeManyToManys: meta.largeManyToManys.map((field) => ({ ...field })),
21
+ polymorphics: meta.polymorphics.map((field) => ({
22
+ ...field,
23
+ components: field.components.map((component) => ({ ...component }))
24
+ })),
25
+ nonDeferredFks: meta.nonDeferredFks,
26
+ nonDeferredManyToManyFks: meta.nonDeferredManyToManyFks
27
+ };
28
+ for (const timestamp of [
29
+ "createdAt",
30
+ "updatedAt",
31
+ "deletedAt"
32
+ ]) meta.physicalMetadata[timestamp] = meta.physicalMetadata.primitives.find((field) => field.fieldName === meta[timestamp]?.fieldName);
33
+ }
7
34
  setClassTableInheritance(entities, entitiesByName);
8
35
  expandSingleTableInheritance(config, entitiesByName, entities);
9
36
  rewriteSingleTableForeignKeys(config, entities);
@@ -100,6 +127,7 @@ function expandSingleTableInheritance(config, entitiesByName, entities) {
100
127
  name: subTypeName,
101
128
  entity: makeEntity(subTypeName),
102
129
  tableName: entity.tableName,
130
+ physicalMetadata: entity.physicalMetadata,
103
131
  primaryKey: entity.primaryKey,
104
132
  primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
105
133
  enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),
@@ -1 +1 @@
1
- {"version":3,"file":"inheritance.js","names":[],"sources":["../src/inheritance.ts"],"sourcesContent":["import { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type ManyToManyField,\n type ManyToOneField,\n type PolymorphicFieldComponent,\n canonicalizeOtherEntities,\n makeEntity,\n} from \"./EntityDbMetadata.ts\";\nimport { fail } from \"./utils.ts\";\n\nexport function applyInheritanceUpdates(config: Config, db: DbMetadata): void {\n const { entities, entitiesByName } = db;\n setClassTableInheritance(entities, entitiesByName);\n expandSingleTableInheritance(config, entitiesByName, entities);\n rewriteSingleTableForeignKeys(config, entities);\n setupSubTypeSpecialization(config, entities);\n // Now that all relations (incl. specialized ones) exist, collapse the duplicate `otherEntity` objects\n canonicalizeOtherEntities(db);\n}\n\n/**\n * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.\n *\n * I.e. `SmallPublishers.group: SmallPublisherGroup`.\n *\n * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,\n * once for the base and once for the child, which is unusual, but gets the types generated\n * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating\n * `meta.allFields`.\n */\nfunction setupSubTypeSpecialization(config: Config, entities: EntityDbMetadata[]): void {\n for (const entity of entities) {\n if (entity.baseType) {\n const entityConfig = config.entities[entity.name];\n const baseConfig = config.entities[entity.baseType.name];\n // Look through the base's m2os & o2ms, looking for a config specialization\n for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {\n const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};\n const subType =\n entityConfig?.relations?.[rel.fieldName]?.subType ??\n baseConfig?.relations?.[rel.fieldName]?.subType ??\n // Probe the otherFieldName for a `subType: \"self\"` on self-referential relations in STI tables\n baseConfig?.relations?.[rel.otherFieldName]?.subType ??\n // if we are only marking the relation as required and not specifying a subtype, then use the original type\n (notNull ? rel.otherEntity.name : undefined);\n\n if (!subType) {\n // continue...\n } else if (subType === \"self\" && rel.kind === \"m2o\") {\n // Specialize `TaskNew.copiedFrom: TaskNew` & `TaskOld.copiedFrom: TaskOld`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (subType === \"self\" && rel.kind === \"o2m\") {\n // Specialize `TaskNew.copiedTo: TaskNew[]` & `TaskOld.copiedTo: TaskOld[]`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (rel.kind === \"m2o\") {\n // Specialize `SmallPublisher.group: SmallPublisherGroup`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n } else if (rel.kind === \"o2m\") {\n // Specialize `SmallPublisherGroup.publishers: SmallPublisher`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n }\n }\n\n // Look through the base's primitives looking for a config specialization\n for (const field of entity.baseType?.primitives ?? []) {\n // the only specialization a primitive can have is nullability\n const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};\n if (notNull) {\n entity.primitives.push({ ...field, notNull });\n }\n }\n }\n }\n}\n\n/**\n * Ensure CTI base types have their inheritanceType set.\n *\n * (We automatically set `inheritanceType` for STI tables when we see their config\n * setup, see `expandSingleTableInheritance`.)\n */\nfunction setClassTableInheritance(\n entities: EntityDbMetadata[],\n entitiesByName: Record<string, EntityDbMetadata>,\n): void {\n const ctiBaseNames: string[] = [];\n for (const entity of entities) {\n if (entity.baseClassName) {\n ctiBaseNames.push(entity.baseClassName);\n const base = entitiesByName[entity.baseClassName];\n entity.baseType = base;\n base.subTypes.push(entity);\n }\n }\n for (const entity of entities) {\n if (ctiBaseNames.includes(entity.name)) entity.inheritanceType = \"cti\";\n }\n}\n\n/** Expands STI tables into multiple entities, so they get separate `SubTypeCodegen.ts` & `SubType.ts` files. */\nfunction expandSingleTableInheritance(\n config: Config,\n entitiesByName: Record<string, EntityDbMetadata>,\n entities: EntityDbMetadata[],\n): void {\n for (const entity of entities) {\n const [fieldName, stiField] =\n Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];\n if (fieldName && stiField && stiField.stiDiscriminator) {\n entity.inheritanceType = \"sti\";\n\n // Ensure we have an enum field so that we can bake the STI discriminators into the metadata.ts file\n const enumField =\n entity.enums.find((e) => e.fieldName === fieldName) ??\n fail(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);\n entity.stiDiscriminatorField = enumField.fieldName;\n\n // Find the available discriminators/subtypes, i.e. NEW => NewTask, OLD => OldTask, etc.\n const subTypes = Object.entries(stiField.stiDiscriminator);\n\n const allFields = [\n ...Object.entries(config.entities[entity.name]?.fields ?? {}),\n ...Object.entries(config.entities[entity.name]?.relations ?? {}),\n ];\n\n // Make sure there aren't any typos in `stiType`s\n const availableCodes = subTypes.map(([code]) => code);\n const availableNames = subTypes.map(([, name]) => name);\n const available = [...availableCodes, ...availableNames];\n allFields.filter(([name, f]) => {\n if (f.stiType && !available.includes(f.stiType)) {\n fail(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(\", \")}`);\n }\n });\n\n // Now split each subType out into its out entity\n for (const [enumCode, subTypeName] of subTypes) {\n // Find all the base entity's fields that belong to us\n const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);\n const subTypeFieldNames = subTypeFields.map(([name]) => name);\n\n // Make fields as required\n function maybeRequired<T extends { notNull: boolean; fieldName: string }>(field: T): T {\n const config = subTypeFields.find(([name]) => name === field.fieldName)?.[1]!;\n if (config.notNull) field.notNull = true;\n return field;\n }\n\n // Synthesize an entity for this STI sub-entity\n const subEntity: EntityDbMetadata = {\n name: subTypeName,\n entity: makeEntity(subTypeName),\n tableName: entity.tableName,\n primaryKey: entity.primaryKey,\n primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n tagName: entity.tagName,\n createdAt: undefined,\n updatedAt: undefined,\n deletedAt: undefined,\n baseClassName: entity.name,\n baseType: entity,\n subTypes: [],\n inheritanceType: \"sti\",\n stiDiscriminatorValue: (\n enumField.enumRows.find((r) => r.code === enumCode) ??\n fail(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)\n ).id,\n abstract: false,\n nonDeferredFkOrder: entity.nonDeferredFkOrder,\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 get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n },\n };\n\n // Now strip all the subclass fields from the base class\n entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.subTypes.push(subEntity);\n\n entities.push(subEntity);\n entitiesByName[subEntity.name] = subEntity;\n }\n }\n }\n}\n\ntype StiEntityMap = Map<string, { base: EntityDbMetadata; subTypes: EntityDbMetadata[] }>;\nlet stiEntities: StiEntityMap;\n\nexport function getStiEntities(entities: EntityDbMetadata[]): StiEntityMap {\n if (stiEntities) return stiEntities;\n stiEntities = new Map();\n for (const entity of entities) {\n if (entity.inheritanceType === \"sti\" && entity.stiDiscriminatorField) {\n const base = entity;\n const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);\n stiEntities.set(entity.name, { base, subTypes });\n // Allow looking up by subType name\n for (const subType of subTypes) {\n stiEntities.set(subType.name, { base, subTypes: [] });\n }\n }\n }\n return stiEntities;\n}\n\n/** Finds FKs pointing to the base table and, if configured, rewrites them to point to the sub-tables. */\nfunction rewriteSingleTableForeignKeys(config: Config, entities: EntityDbMetadata[]): void {\n // See if we even have any STI tables\n const stiEntities = getStiEntities(entities);\n if (stiEntities.size === 0) return;\n // Scan for other entities/relations that point to the STI table\n for (const entity of entities) {\n // m2os -- Look for `entity.task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const m2o of entity.manyToOnes) {\n const target = stiEntities.get(m2o.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n m2o.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n // polys -- Look for `entity.parent_task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const poly of entity.polymorphics) {\n for (const comp of poly.components) {\n const target = stiEntities.get(comp.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n comp.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n }\n // o2ms -- Look for `entity.tasks` collections loading `task.entity_id`, but entity has been pushed down to `TaskOld`\n for (const o2m of entity.oneToManys) {\n const target = stiEntities.get(o2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) &&\n st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName),\n );\n if (otherField) {\n o2m.otherEntity = otherField.entity;\n }\n }\n }\n // m2ms -- Look for `entity.tasks` collections loading m2m rows, but `entity` has been pushed down to `TaskOld`\n for (const m2m of entity.manyToManys) {\n const target = stiEntities.get(m2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) &&\n st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName),\n );\n if (otherField) {\n m2m.otherEntity = otherField.entity;\n }\n }\n }\n }\n}\n"],"mappings":";;;;AAYA,SAAgB,wBAAwB,QAAgB,IAAsB;CAC5E,MAAM,EAAE,UAAU,mBAAmB;CACrC,yBAAyB,UAAU,cAAc;CACjD,6BAA6B,QAAQ,gBAAgB,QAAQ;CAC7D,8BAA8B,QAAQ,QAAQ;CAC9C,2BAA2B,QAAQ,QAAQ;CAE3C,0BAA0B,EAAE;AAC9B;;;;;;;;;;;AAYA,SAAS,2BAA2B,QAAgB,UAAoC;CACtF,KA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AM,EAAE,cAAc,IAAI,cAAc,CACjE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;CACF;AACF"}
1
+ {"version":3,"file":"inheritance.js","names":[],"sources":["../src/inheritance.ts"],"sourcesContent":["import { type Config } from \"./config.ts\";\nimport {\n type DbMetadata,\n type EntityDbMetadata,\n type ManyToManyField,\n type ManyToOneField,\n type PolymorphicFieldComponent,\n canonicalizeOtherEntities,\n makeEntity,\n} from \"./EntityDbMetadata.ts\";\nimport { fail } from \"./utils.ts\";\n\n/** Preserves physical storage metadata, then applies domain inheritance specialization. */\nexport function applyInheritanceUpdates(config: Config, db: DbMetadata): void {\n const { entities, entitiesByName } = db;\n // Preserve storage domains before STI moves fields or rewrites relationship targets.\n for (const meta of entities) {\n meta.physicalMetadata = {\n ...meta,\n name: meta.name,\n primitives: meta.primitives.map((field) => ({ ...field })),\n enums: meta.enums.map((field) => ({ ...field })),\n pgEnums: meta.pgEnums.map((field) => ({ ...field })),\n manyToOnes: meta.manyToOnes.map((field) => ({ ...field })),\n oneToManys: meta.oneToManys.map((field) => ({ ...field })),\n largeOneToManys: meta.largeOneToManys.map((field) => ({ ...field })),\n oneToOnes: meta.oneToOnes.map((field) => ({ ...field })),\n manyToManys: meta.manyToManys.map((field) => ({ ...field })),\n largeManyToManys: meta.largeManyToManys.map((field) => ({ ...field })),\n polymorphics: meta.polymorphics.map((field) => ({\n ...field,\n components: field.components.map((component) => ({ ...component })),\n })),\n nonDeferredFks: meta.nonDeferredFks,\n nonDeferredManyToManyFks: meta.nonDeferredManyToManyFks,\n };\n for (const timestamp of [\"createdAt\", \"updatedAt\", \"deletedAt\"] as const) {\n meta.physicalMetadata[timestamp] = meta.physicalMetadata.primitives.find(\n (field) => field.fieldName === meta[timestamp]?.fieldName,\n );\n }\n }\n setClassTableInheritance(entities, entitiesByName);\n expandSingleTableInheritance(config, entitiesByName, entities);\n rewriteSingleTableForeignKeys(config, entities);\n setupSubTypeSpecialization(config, entities);\n // Now that all relations (incl. specialized ones) exist, collapse the duplicate `otherEntity` objects\n canonicalizeOtherEntities(db);\n}\n\n/**\n * Looks for subtypes specializing a FK of their base type, and give them a specialized m2o.\n *\n * I.e. `SmallPublishers.group: SmallPublisherGroup`.\n *\n * This means the `publishers.group_id` FK will actually be in the `EntityDbMetadata` twice,\n * once for the base and once for the child, which is unusual, but gets the types generated\n * that we want, and then we fixup/dedupe them at runtime in `configure.ts` when creating\n * `meta.allFields`.\n */\nfunction setupSubTypeSpecialization(config: Config, entities: EntityDbMetadata[]): void {\n for (const entity of entities) {\n if (entity.baseType) {\n const entityConfig = config.entities[entity.name];\n const baseConfig = config.entities[entity.baseType.name];\n // Look through the base's m2os & o2ms, looking for a config specialization\n for (const rel of [...entity.baseType.manyToOnes, ...entity.baseType.oneToManys]) {\n const { notNull } = entityConfig?.relations?.[rel.fieldName] ?? {};\n const subType =\n entityConfig?.relations?.[rel.fieldName]?.subType ??\n baseConfig?.relations?.[rel.fieldName]?.subType ??\n // Probe the otherFieldName for a `subType: \"self\"` on self-referential relations in STI tables\n baseConfig?.relations?.[rel.otherFieldName]?.subType ??\n // if we are only marking the relation as required and not specifying a subtype, then use the original type\n (notNull ? rel.otherEntity.name : undefined);\n\n if (!subType) {\n // continue...\n } else if (subType === \"self\" && rel.kind === \"m2o\") {\n // Specialize `TaskNew.copiedFrom: TaskNew` & `TaskOld.copiedFrom: TaskOld`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (subType === \"self\" && rel.kind === \"o2m\") {\n // Specialize `TaskNew.copiedTo: TaskNew[]` & `TaskOld.copiedTo: TaskOld[]`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(entity.name) });\n } else if (rel.kind === \"m2o\") {\n // Specialize `SmallPublisher.group: SmallPublisherGroup`\n entity.manyToOnes.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n } else if (rel.kind === \"o2m\") {\n // Specialize `SmallPublisherGroup.publishers: SmallPublisher`\n entity.oneToManys.push({ ...rel, ...(notNull ? { notNull } : {}), otherEntity: makeEntity(subType) });\n }\n }\n\n // Look through the base's primitives looking for a config specialization\n for (const field of entity.baseType?.primitives ?? []) {\n // the only specialization a primitive can have is nullability\n const { notNull } = entityConfig?.fields?.[field.fieldName] ?? {};\n if (notNull) {\n entity.primitives.push({ ...field, notNull });\n }\n }\n }\n }\n}\n\n/**\n * Ensure CTI base types have their inheritanceType set.\n *\n * (We automatically set `inheritanceType` for STI tables when we see their config\n * setup, see `expandSingleTableInheritance`.)\n */\nfunction setClassTableInheritance(\n entities: EntityDbMetadata[],\n entitiesByName: Record<string, EntityDbMetadata>,\n): void {\n const ctiBaseNames: string[] = [];\n for (const entity of entities) {\n if (entity.baseClassName) {\n ctiBaseNames.push(entity.baseClassName);\n const base = entitiesByName[entity.baseClassName];\n entity.baseType = base;\n base.subTypes.push(entity);\n }\n }\n for (const entity of entities) {\n if (ctiBaseNames.includes(entity.name)) entity.inheritanceType = \"cti\";\n }\n}\n\n/** Expands STI tables into multiple entities, so they get separate `SubTypeCodegen.ts` & `SubType.ts` files. */\nfunction expandSingleTableInheritance(\n config: Config,\n entitiesByName: Record<string, EntityDbMetadata>,\n entities: EntityDbMetadata[],\n): void {\n for (const entity of entities) {\n const [fieldName, stiField] =\n Object.entries(config.entities[entity.name]?.fields || {}).find(([, f]) => !!f.stiDiscriminator) ?? [];\n if (fieldName && stiField && stiField.stiDiscriminator) {\n entity.inheritanceType = \"sti\";\n\n // Ensure we have an enum field so that we can bake the STI discriminators into the metadata.ts file\n const enumField =\n entity.enums.find((e) => e.fieldName === fieldName) ??\n fail(`No enum column found for ${entity.name}.${fieldName}, which is required to use singleTableInheritance`);\n entity.stiDiscriminatorField = enumField.fieldName;\n\n // Find the available discriminators/subtypes, i.e. NEW => NewTask, OLD => OldTask, etc.\n const subTypes = Object.entries(stiField.stiDiscriminator);\n\n const allFields = [\n ...Object.entries(config.entities[entity.name]?.fields ?? {}),\n ...Object.entries(config.entities[entity.name]?.relations ?? {}),\n ];\n\n // Make sure there aren't any typos in `stiType`s\n const availableCodes = subTypes.map(([code]) => code);\n const availableNames = subTypes.map(([, name]) => name);\n const available = [...availableCodes, ...availableNames];\n allFields.filter(([name, f]) => {\n if (f.stiType && !available.includes(f.stiType)) {\n fail(`${name}.stiType '${f.stiType}' is invalid, expected one of ${available.join(\", \")}`);\n }\n });\n\n // Now split each subType out into its out entity\n for (const [enumCode, subTypeName] of subTypes) {\n // Find all the base entity's fields that belong to us\n const subTypeFields = allFields.filter(([, f]) => f.stiType === subTypeName || f.stiType === enumCode);\n const subTypeFieldNames = subTypeFields.map(([name]) => name);\n\n // Make fields as required\n function maybeRequired<T extends { notNull: boolean; fieldName: string }>(field: T): T {\n const config = subTypeFields.find(([name]) => name === field.fieldName)?.[1]!;\n if (config.notNull) field.notNull = true;\n return field;\n }\n\n // Synthesize an entity for this STI sub-entity\n const subEntity: EntityDbMetadata = {\n name: subTypeName,\n entity: makeEntity(subTypeName),\n tableName: entity.tableName,\n physicalMetadata: entity.physicalMetadata,\n primaryKey: entity.primaryKey,\n primitives: entity.primitives.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n enums: entity.enums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n pgEnums: entity.pgEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n manyToOnes: entity.manyToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)).map(maybeRequired),\n oneToManys: entity.oneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeOneToManys: entity.largeOneToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n oneToOnes: entity.oneToOnes.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManys: entity.manyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n largeManyToManys: entity.largeManyToManys.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n manyToManyEnums: entity.manyToManyEnums.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n polymorphics: entity.polymorphics.filter((f) => subTypeFieldNames.includes(f.fieldName)),\n tagName: entity.tagName,\n createdAt: undefined,\n updatedAt: undefined,\n deletedAt: undefined,\n baseClassName: entity.name,\n baseType: entity,\n subTypes: [],\n inheritanceType: \"sti\",\n stiDiscriminatorValue: (\n enumField.enumRows.find((r) => r.code === enumCode) ??\n fail(`No enum row found for ${entity.name}.${fieldName}.${enumCode}`)\n ).id,\n abstract: false,\n nonDeferredFkOrder: entity.nonDeferredFkOrder,\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 get nonDeferredManyToManyFks(): Array<ManyToManyField> {\n return this.manyToManys.filter((r) => !r.isDeferredAndDeferrable);\n },\n };\n\n // Now strip all the subclass fields from the base class\n entity.primitives = entity.primitives.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.enums = entity.enums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.pgEnums = entity.pgEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToOnes = entity.manyToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToManys = entity.oneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeOneToManys = entity.largeOneToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.oneToOnes = entity.oneToOnes.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManys = entity.manyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.largeManyToManys = entity.largeManyToManys.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.manyToManyEnums = entity.manyToManyEnums.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.polymorphics = entity.polymorphics.filter((f) => !subTypeFieldNames.includes(f.fieldName));\n entity.subTypes.push(subEntity);\n\n entities.push(subEntity);\n entitiesByName[subEntity.name] = subEntity;\n }\n }\n }\n}\n\ntype StiEntityMap = Map<string, { base: EntityDbMetadata; subTypes: EntityDbMetadata[] }>;\nlet stiEntities: StiEntityMap;\n\nexport function getStiEntities(entities: EntityDbMetadata[]): StiEntityMap {\n if (stiEntities) return stiEntities;\n stiEntities = new Map();\n for (const entity of entities) {\n if (entity.inheritanceType === \"sti\" && entity.stiDiscriminatorField) {\n const base = entity;\n const subTypes = entities.filter((s) => s.baseClassName === entity.name && s !== entity);\n stiEntities.set(entity.name, { base, subTypes });\n // Allow looking up by subType name\n for (const subType of subTypes) {\n stiEntities.set(subType.name, { base, subTypes: [] });\n }\n }\n }\n return stiEntities;\n}\n\n/** Finds FKs pointing to the base table and, if configured, rewrites them to point to the sub-tables. */\nfunction rewriteSingleTableForeignKeys(config: Config, entities: EntityDbMetadata[]): void {\n // See if we even have any STI tables\n const stiEntities = getStiEntities(entities);\n if (stiEntities.size === 0) return;\n // Scan for other entities/relations that point to the STI table\n for (const entity of entities) {\n // m2os -- Look for `entity.task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const m2o of entity.manyToOnes) {\n const target = stiEntities.get(m2o.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[m2o.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n m2o.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n // polys -- Look for `entity.parent_task_id` FKs pointing at `Task` and, if configured, rewrite them to point at `TaskOld`\n for (const poly of entity.polymorphics) {\n for (const comp of poly.components) {\n const target = stiEntities.get(comp.otherEntity.name);\n const base = target?.base.entity.name;\n // See if the user has pushed `Task.entities` down to a subtype\n const stiType = base && config.entities[base]?.relations?.[comp.otherFieldName]?.stiType;\n if (target && stiType) {\n const { subTypes } = target;\n comp.otherEntity = (\n subTypes.find((s) => s.name === stiType) ??\n fail(`Could not find STI type '${stiType}' in ${subTypes.map((s) => s.name)}`)\n ).entity;\n }\n }\n }\n // o2ms -- Look for `entity.tasks` collections loading `task.entity_id`, but entity has been pushed down to `TaskOld`\n for (const o2m of entity.oneToManys) {\n const target = stiEntities.get(o2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName) &&\n st.manyToOnes.some((m) => m.fieldName === o2m.otherFieldName),\n );\n if (otherField) {\n o2m.otherEntity = otherField.entity;\n }\n }\n }\n // m2ms -- Look for `entity.tasks` collections loading m2m rows, but `entity` has been pushed down to `TaskOld`\n for (const m2m of entity.manyToManys) {\n const target = stiEntities.get(m2m.otherEntity.name);\n if (target && target.base.inheritanceType === \"sti\") {\n // Ensure the incoming FK is not in the base type, and find the 1st subtype (eventually N subtypes?)\n const otherField = target.subTypes.find(\n (st) =>\n !target.base.manyToManys.some((m) => m.fieldName === m2m.otherFieldName) &&\n st.manyToManys.some((m) => m.fieldName === m2m.otherFieldName),\n );\n if (otherField) {\n m2m.otherEntity = otherField.entity;\n }\n }\n }\n }\n}\n"],"mappings":";;;;;AAaA,SAAgB,wBAAwB,QAAgB,IAAsB;CAC5E,MAAM,EAAE,UAAU,mBAAmB;CAErC,KAAK,MAAM,QAAQ,UAAU;EAC3B,KAAK,mBAAmB;GACtB,GAAG;GACH,MAAM,KAAK;GACX,YAAY,KAAK,WAAW,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GACzD,OAAO,KAAK,MAAM,KAAK,WAAW,EAAE,GAAG,MAAM,EAAE;GAC/C,SAAS,KAAK,QAAQ,KAAK,WAAW,EAAE,GAA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AAY,IAAI,KAAK,YAAY,IAAI;GACpD,MAAM,OAAO,QAAQ,KAAK,OAAO;GAEjC,MAAM,UAAU,QAAQ,OAAO,SAAS,KAAK,EAAE,YAAY,KAAK,eAAe,EAAE;GACjF,IAAI,UAAU,SAAS;IACrB,MAAM,EAAE,aAAa;IACrB,KAAK,eACH,SAAS,MAAM,MAAM,EAAE,SAAS,OAAO,KACvC,KAAK,4BAA4B,QAAQ,OAAO,SAAS,KAAK,MAAM,EAAE,IAAI,GAAG,EAAA,CAC7E;GACJ;EACF;EAGF,KAAK,MAAM,OAAO,OAAO,YAAY;GACnC,MAAM,SAAS,YAAY,IAAI,IAAI,YAAY,IAAI;GACnD,IAAI,UAAU,OAAO,KAAK,oBAAoB,OAAO;IAEnD,MAAM,aAAa,OAAO,SAAS,MAChC,OACC,CAAC,OAAO,KAAK,WAAW,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,KACtE,GAAG,WAAW,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,CAChE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;EAEA,KAAK,MAAM,OAAO,OAAO,aAAa;GACpC,MAAM,SAAS,YAAY,IAAI,IAAI,YAAY,IAAI;GACnD,IAAI,UAAU,OAAO,KAAK,oBAAoB,OAAO;IAEnD,MAAM,aAAa,OAAO,SAAS,MAChC,OACC,CAAC,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,KACvE,GAAG,YAAY,MAAM,MAAM,EAAE,cAAc,IAAI,cAAc,CACjE;IACA,IAAI,YACF,IAAI,cAAc,WAAW;GAEjC;EACF;CACF;AACF"}
package/build/symbols.cjs CHANGED
@@ -20,6 +20,11 @@ const EntityMetadata = (0, ts_poet.imp)("t:EntityMetadata@joist-orm");
20
20
  const EnumMetadata = (0, ts_poet.imp)("t:EnumMetadata@joist-orm");
21
21
  const Lens = (0, ts_poet.imp)("t:Lens@joist-orm");
22
22
  const KeySerde = (0, ts_poet.imp)("KeySerde@joist-orm");
23
+ const Column = (0, ts_poet.imp)("Column@joist-orm");
24
+ const ColumnDescriptors = (0, ts_poet.imp)("t:ColumnDescriptors@joist-orm");
25
+ const SimpleFieldSerde = (0, ts_poet.imp)("SimpleFieldSerde@joist-orm");
26
+ const PolyComponent = (0, ts_poet.imp)("PolyComponent@joist-orm");
27
+ const polymorphicField = (0, ts_poet.imp)("polymorphicField@joist-orm");
23
28
  const ManyToOneReference = (0, ts_poet.imp)("t:ManyToOneReference@joist-orm");
24
29
  const LazyField = (0, ts_poet.imp)("t:LazyField@joist-orm");
25
30
  const hasLazyField = (0, ts_poet.imp)("hasLazyField@joist-orm");
@@ -119,6 +124,8 @@ exports.BooleanFilter = BooleanFilter;
119
124
  exports.BooleanGraphQLFilter = BooleanGraphQLFilter;
120
125
  exports.Changes = Changes;
121
126
  exports.Collection = Collection;
127
+ exports.Column = Column;
128
+ exports.ColumnDescriptors = ColumnDescriptors;
122
129
  exports.ConfigApi = ConfigApi;
123
130
  exports.CustomSerdeAdapter = CustomSerdeAdapter;
124
131
  exports.DateSerde = DateSerde;
@@ -165,6 +172,7 @@ exports.PartialOrNull = PartialOrNull;
165
172
  exports.PlainDateSerde = PlainDateSerde;
166
173
  exports.PlainDateTimeSerde = PlainDateTimeSerde;
167
174
  exports.PlainTimeSerde = PlainTimeSerde;
175
+ exports.PolyComponent = PolyComponent;
168
176
  exports.PolymorphicKeySerde = PolymorphicKeySerde;
169
177
  exports.PolymorphicReference = PolymorphicReference;
170
178
  exports.PrimitiveSerde = PrimitiveSerde;
@@ -178,6 +186,7 @@ exports.Reference = Reference;
178
186
  exports.RelationsOf = RelationsOf;
179
187
  exports.SSAssert = SSAssert;
180
188
  exports.Scope = Scope;
189
+ exports.SimpleFieldSerde = SimpleFieldSerde;
181
190
  exports.SuperstructSerde = SuperstructSerde;
182
191
  exports.TaggedId = TaggedId;
183
192
  exports.ToJsonHint = ToJsonHint;
@@ -218,6 +227,7 @@ exports.newRequiredRule = newRequiredRule;
218
227
  exports.newScopeFn = newScopeFn;
219
228
  exports.newTestInstance = newTestInstance;
220
229
  exports.nowUTC = nowUTC;
230
+ exports.polymorphicField = polymorphicField;
221
231
  exports.setField = setField;
222
232
  exports.setOpts = setOpts;
223
233
  exports.setRuntimeConfig = setRuntimeConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"symbols.cjs","names":["imp"],"sources":["../src/symbols.ts"],"sourcesContent":["import { imp } from \"ts-poet\";\n\nexport const ProjectEntity = imp(`t:Entity@./entities.ts`);\nexport const EntityManager = imp(\"EntityManager@./entities.ts\");\n\nexport const ConfigApi = imp(\"ConfigApi@joist-orm\");\nexport const newScopeFn = imp(\"newScopeFn@joist-orm\");\nexport const Scope = imp(\"t:Scope@joist-orm\");\nexport const FieldStatus = imp(\"t:FieldStatus@joist-orm\");\nexport const Entity = imp(\"t:Entity@joist-orm\");\nexport const BaseEntity = imp(\"BaseEntity@joist-orm\");\nexport const Flavor = imp(\"t:Flavor@joist-orm\");\nexport const Reference = imp(\"t:Reference@joist-orm\");\nexport const Collection = imp(\"t:Collection@joist-orm\");\nexport const EnumCollection = imp(\"t:EnumCollection@joist-orm\");\nexport const LargeCollection = imp(\"t:LargeCollection@joist-orm\");\nexport const OneToManyCollection = imp(\"OneToManyCollection@joist-orm\");\nexport const JoistEntityManager = imp(\"EntityManager@joist-orm\");\nexport const EntityMetadata = imp(\"t:EntityMetadata@joist-orm\");\nexport const EnumMetadata = imp(\"t:EnumMetadata@joist-orm\");\nexport const Lens = imp(\"t:Lens@joist-orm\");\nexport const KeySerde = imp(\"KeySerde@joist-orm\");\nexport const ManyToOneReference = imp(\"t:ManyToOneReference@joist-orm\");\nexport const LazyField = imp(\"t:LazyField@joist-orm\");\nexport const hasLazyField = imp(\"hasLazyField@joist-orm\");\nexport const ReadOnlyCollection = imp(\"t:ReadOnlyCollection@joist-orm\");\nexport const PolymorphicReference = imp(\"t:PolymorphicReference@joist-orm\");\nexport const OneToOneReference = imp(\"t:OneToOneReference@joist-orm\");\nexport const ManyToManyCollection = imp(\"ManyToManyCollection@joist-orm\");\nexport const EnumFieldSerde = imp(\"EnumFieldSerde@joist-orm\");\nexport const EnumArrayFieldSerde = imp(\"EnumArrayFieldSerde@joist-orm\");\nexport const PolymorphicKeySerde = imp(\"PolymorphicKeySerde@joist-orm\");\nexport const PrimitiveSerde = imp(\"PrimitiveSerde@joist-orm\");\nexport const BigIntSerde = imp(\"BigIntSerde@joist-orm\");\nexport const DateSerde = imp(\"DateSerde@joist-orm\");\nexport const PlainDateSerde = imp(\"PlainDateSerde@joist-orm\");\nexport const PlainTimeSerde = imp(\"PlainTimeSerde@joist-orm\");\nexport const PlainDateTimeSerde = imp(\"PlainDateTimeSerde@joist-orm\");\nexport const ZonedDateTimeSerde = imp(\"ZonedDateTimeSerde@joist-orm\");\nexport const JsonSerde = imp(\"JsonSerde@joist-orm\");\nexport const SuperstructSerde = imp(\"SuperstructSerde@joist-orm\");\nexport const TaggedId = imp(\"t:TaggedId@joist-orm\");\nexport const ZodSerde = imp(\"ZodSerde@joist-orm\");\nexport const CustomSerdeAdapter = imp(\"CustomSerdeAdapter@joist-orm\");\nexport const DecimalToNumberSerde = imp(\"DecimalToNumberSerde@joist-orm\");\nexport const fail = imp(\"fail@joist-orm\");\nexport const failNoIdYet = imp(\"failNoIdYet@joist-orm\");\nexport const setOpts = imp(\"setOpts@joist-orm\");\nexport const getField = imp(\"getField@joist-orm\");\nexport const setField = imp(\"setField@joist-orm\");\nexport const OrderBy = imp(\"t:OrderBy@joist-orm\");\nexport const OptsOf = imp(\"t:OptsOf@joist-orm\");\nexport const FieldsOf = imp(\"t:FieldsOf@joist-orm\");\nexport const RelationsOf = imp(\"t:RelationsOf@joist-orm\");\nexport const IdOf = imp(\"t:IdOf@joist-orm\");\nexport const PartialOrNull = imp(\"t:PartialOrNull@joist-orm\");\nexport const DeepPartialOrNull = imp(\"t:DeepPartialOrNull@joist-orm\");\nexport const BooleanFilter = imp(\"t:BooleanFilter@joist-orm\");\nexport const ValueFilter = imp(\"t:ValueFilter@joist-orm\");\nexport const EntityFilter = imp(\"t:EntityFilter@joist-orm\");\nexport const BooleanGraphQLFilter = imp(\"t:BooleanGraphQLFilter@joist-orm\");\nexport const EntityGraphQLFilter = imp(\"t:EntityGraphQLFilter@joist-orm\");\nexport const EnumGraphQLFilter = imp(\"t:EnumGraphQLFilter@joist-orm\");\nexport const ValueGraphQLFilter = imp(\"t:ValueGraphQLFilter@joist-orm\");\nexport const FilterOf = imp(\"t:FilterOf@joist-orm\");\nexport const GraphQLFilterOf = imp(\"t:GraphQLFilterOf@joist-orm\");\nexport const JsonHint = imp(\"t:JsonHint@joist-orm\");\nexport const ToJsonHint = imp(\"t:ToJsonHint@joist-orm\");\nexport const JsonPayload = imp(\"t:JsonPayload@joist-orm\");\nexport const configureMetadata = imp(\"configureMetadata@joist-orm\");\nexport const newRequiredRule = imp(\"newRequiredRule@joist-orm\");\nexport const newRequiredLazyFieldRule = imp(\"newRequiredLazyFieldRule@joist-orm\");\nexport const cannotBeUpdated = imp(\"cannotBeUpdated@joist-orm\");\nexport const mustBeSubType = imp(\"mustBeSubType@joist-orm\");\nexport const cleanStringValue = imp(\"cleanStringValue@joist-orm\");\nexport const Changes = imp(\"t:Changes@joist-orm\");\nexport const newChangesProxy = imp(\"newChangesProxy@joist-orm\");\nexport const nowUTC = imp(\"nowUTC@joist-orm\");\nexport const LoadHint = imp(\"t:LoadHint@joist-orm\");\nexport const Loaded = imp(\"t:Loaded@joist-orm\");\nexport const isLoaded = imp(\"isLoaded@joist-orm\");\nexport const getInstanceData = imp(\"getInstanceData@joist-orm\");\nexport const isEntity = imp(\"isEntity@joist-orm\");\nexport const loadLens = imp(\"loadLens@joist-orm\");\nexport const hasOneThrough = imp(\"hasOneThrough@joist-orm\");\nexport const hasMany = imp(\"hasMany@joist-orm\");\nexport const hasLargeMany = imp(\"hasLargeMany@joist-orm\");\nexport const hasOne = imp(\"hasOne@joist-orm\");\nexport const hasRecursiveChildren = imp(\"hasRecursiveChildren@joist-orm\");\nexport const hasRecursiveM2m = imp(\"hasRecursiveM2m@joist-orm\");\nexport const hasRecursiveParents = imp(\"hasRecursiveParents@joist-orm\");\nexport const hasOnePolymorphic = imp(\"hasOnePolymorphic@joist-orm\");\nexport const hasOneToOne = imp(\"hasOneToOne@joist-orm\");\nexport const hasManyToMany = imp(\"hasManyToMany@joist-orm\");\nexport const hasEnumCollection = imp(\"hasEnumCollection@joist-orm\");\nexport const hasLargeManyToMany = imp(\"hasLargeManyToMany@joist-orm\");\nexport const newTestInstance = imp(\"newTestInstance@joist-orm\");\nexport const New = imp(\"t:New@joist-orm\");\nexport const DeepNew = imp(\"t:DeepNew@joist-orm\");\nexport const FactoryOpts = imp(\"t:FactoryOpts@joist-orm\");\nexport const SSAssert = imp(\"assert@superstruct\");\nexport const Zod = imp(\"z@zod\");\nexport const EntityConstructor = imp(\"t:EntityConstructor@joist-orm\");\nexport const MaybeAbstractEntityConstructor = imp(\"t:MaybeAbstractEntityConstructor@joist-orm\");\nexport const deTagId = imp(\"deTagId@joist-orm\");\nexport const toIdOf = imp(\"toIdOf@joist-orm\");\nexport const toJSON = imp(\"toJSON@joist-orm\");\nexport const ReactiveField = imp(\"t:ReactiveField@joist-orm\");\nexport const ReactiveReference = imp(\"t:ReactiveReference@joist-orm\");\nexport const ReactiveManyToMany = imp(\"t:ReactiveManyToMany@joist-orm\");\nexport const ReactiveManyToManyOtherSide = imp(\"t:ReactiveManyToManyOtherSide@joist-orm\");\nexport const hasReactiveManyToManyOtherSide = imp(\"hasReactiveManyToManyOtherSide@joist-orm\");\nexport const updatePartial = imp(\"updatePartial@joist-orm\");\nexport const setRuntimeConfig = imp(\"setRuntimeConfig@joist-orm\");\n"],"mappings":";;;AAEA,MAAa,iBAAA,GAAgBA,QAAAA,IAAAA,CAAI,wBAAwB;AACzD,MAAa,iBAAA,GAAgBA,QAAAA,IAAAA,CAAI,6BAA6B;AAE9D,MAAa,aAAA,GAAYA,QA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entity@./entities.ts`);\nexport const EntityManager = imp(\"EntityManager@./entities.ts\");\n\nexport const ConfigApi = imp(\"ConfigApi@joist-orm\");\nexport const newScopeFn = imp(\"newScopeFn@joist-orm\");\nexport const Scope = imp(\"t:Scope@joist-orm\");\nexport const FieldStatus = imp(\"t:FieldStatus@joist-orm\");\nexport const Entity = imp(\"t:Entity@joist-orm\");\nexport const BaseEntity = imp(\"BaseEntity@joist-orm\");\nexport const Flavor = imp(\"t:Flavor@joist-orm\");\nexport const Reference = imp(\"t:Reference@joist-orm\");\nexport const Collection = imp(\"t:Collection@joist-orm\");\nexport const EnumCollection = imp(\"t:EnumCollection@joist-orm\");\nexport const LargeCollection = imp(\"t:LargeCollection@joist-orm\");\nexport const OneToManyCollection = imp(\"OneToManyCollection@joist-orm\");\nexport const JoistEntityManager = imp(\"EntityManager@joist-orm\");\nexport const EntityMetadata = imp(\"t:EntityMetadata@joist-orm\");\nexport const EnumMetadata = imp(\"t:EnumMetadata@joist-orm\");\nexport const Lens = imp(\"t:Lens@joist-orm\");\nexport const KeySerde = imp(\"KeySerde@joist-orm\");\nexport const Column = imp(\"Column@joist-orm\");\nexport const ColumnDescriptors = imp(\"t:ColumnDescriptors@joist-orm\");\nexport const SimpleFieldSerde = imp(\"SimpleFieldSerde@joist-orm\");\nexport const PolyComponent = imp(\"PolyComponent@joist-orm\");\nexport const polymorphicField = imp(\"polymorphicField@joist-orm\");\nexport const ManyToOneReference = imp(\"t:ManyToOneReference@joist-orm\");\nexport const LazyField = imp(\"t:LazyField@joist-orm\");\nexport const hasLazyField = imp(\"hasLazyField@joist-orm\");\nexport const ReadOnlyCollection = imp(\"t:ReadOnlyCollection@joist-orm\");\nexport const PolymorphicReference = imp(\"t:PolymorphicReference@joist-orm\");\nexport const OneToOneReference = imp(\"t:OneToOneReference@joist-orm\");\nexport const ManyToManyCollection = imp(\"ManyToManyCollection@joist-orm\");\nexport const EnumFieldSerde = imp(\"EnumFieldSerde@joist-orm\");\nexport const EnumArrayFieldSerde = imp(\"EnumArrayFieldSerde@joist-orm\");\nexport const PolymorphicKeySerde = imp(\"PolymorphicKeySerde@joist-orm\");\nexport const PrimitiveSerde = imp(\"PrimitiveSerde@joist-orm\");\nexport const BigIntSerde = imp(\"BigIntSerde@joist-orm\");\nexport const DateSerde = imp(\"DateSerde@joist-orm\");\nexport const PlainDateSerde = imp(\"PlainDateSerde@joist-orm\");\nexport const PlainTimeSerde = imp(\"PlainTimeSerde@joist-orm\");\nexport const PlainDateTimeSerde = imp(\"PlainDateTimeSerde@joist-orm\");\nexport const ZonedDateTimeSerde = imp(\"ZonedDateTimeSerde@joist-orm\");\nexport const JsonSerde = imp(\"JsonSerde@joist-orm\");\nexport const SuperstructSerde = imp(\"SuperstructSerde@joist-orm\");\nexport const TaggedId = imp(\"t:TaggedId@joist-orm\");\nexport const ZodSerde = imp(\"ZodSerde@joist-orm\");\nexport const CustomSerdeAdapter = imp(\"CustomSerdeAdapter@joist-orm\");\nexport const DecimalToNumberSerde = imp(\"DecimalToNumberSerde@joist-orm\");\nexport const fail = imp(\"fail@joist-orm\");\nexport const failNoIdYet = imp(\"failNoIdYet@joist-orm\");\nexport const setOpts = imp(\"setOpts@joist-orm\");\nexport const getField = imp(\"getField@joist-orm\");\nexport const setField = imp(\"setField@joist-orm\");\nexport const OrderBy = imp(\"t:OrderBy@joist-orm\");\nexport const OptsOf = imp(\"t:OptsOf@joist-orm\");\nexport const FieldsOf = imp(\"t:FieldsOf@joist-orm\");\nexport const RelationsOf = imp(\"t:RelationsOf@joist-orm\");\nexport const IdOf = imp(\"t:IdOf@joist-orm\");\nexport const PartialOrNull = imp(\"t:PartialOrNull@joist-orm\");\nexport const DeepPartialOrNull = imp(\"t:DeepPartialOrNull@joist-orm\");\nexport const BooleanFilter = imp(\"t:BooleanFilter@joist-orm\");\nexport const ValueFilter = imp(\"t:ValueFilter@joist-orm\");\nexport const EntityFilter = imp(\"t:EntityFilter@joist-orm\");\nexport const BooleanGraphQLFilter = imp(\"t:BooleanGraphQLFilter@joist-orm\");\nexport const EntityGraphQLFilter = imp(\"t:EntityGraphQLFilter@joist-orm\");\nexport const EnumGraphQLFilter = imp(\"t:EnumGraphQLFilter@joist-orm\");\nexport const ValueGraphQLFilter = imp(\"t:ValueGraphQLFilter@joist-orm\");\nexport const FilterOf = imp(\"t:FilterOf@joist-orm\");\nexport const GraphQLFilterOf = imp(\"t:GraphQLFilterOf@joist-orm\");\nexport const JsonHint = imp(\"t:JsonHint@joist-orm\");\nexport const ToJsonHint = imp(\"t:ToJsonHint@joist-orm\");\nexport const JsonPayload = imp(\"t:JsonPayload@joist-orm\");\nexport const configureMetadata = imp(\"configureMetadata@joist-orm\");\nexport const newRequiredRule = imp(\"newRequiredRule@joist-orm\");\nexport const newRequiredLazyFieldRule = imp(\"newRequiredLazyFieldRule@joist-orm\");\nexport const cannotBeUpdated = imp(\"cannotBeUpdated@joist-orm\");\nexport const mustBeSubType = imp(\"mustBeSubType@joist-orm\");\nexport const cleanStringValue = imp(\"cleanStringValue@joist-orm\");\nexport const Changes = imp(\"t:Changes@joist-orm\");\nexport const newChangesProxy = imp(\"newChangesProxy@joist-orm\");\nexport const nowUTC = imp(\"nowUTC@joist-orm\");\nexport const LoadHint = imp(\"t:LoadHint@joist-orm\");\nexport const Loaded = imp(\"t:Loaded@joist-orm\");\nexport const isLoaded = imp(\"isLoaded@joist-orm\");\nexport const getInstanceData = imp(\"getInstanceData@joist-orm\");\nexport const isEntity = imp(\"isEntity@joist-orm\");\nexport const loadLens = imp(\"loadLens@joist-orm\");\nexport const hasOneThrough = imp(\"hasOneThrough@joist-orm\");\nexport const hasMany = imp(\"hasMany@joist-orm\");\nexport const hasLargeMany = imp(\"hasLargeMany@joist-orm\");\nexport const hasOne = imp(\"hasOne@joist-orm\");\nexport const hasRecursiveChildren = imp(\"hasRecursiveChildren@joist-orm\");\nexport const hasRecursiveM2m = imp(\"hasRecursiveM2m@joist-orm\");\nexport const hasRecursiveParents = imp(\"hasRecursiveParents@joist-orm\");\nexport const hasOnePolymorphic = imp(\"hasOnePolymorphic@joist-orm\");\nexport const hasOneToOne = imp(\"hasOneToOne@joist-orm\");\nexport const hasManyToMany = imp(\"hasManyToMany@joist-orm\");\nexport const hasEnumCollection = imp(\"hasEnumCollection@joist-orm\");\nexport const hasLargeManyToMany = imp(\"hasLargeManyToMany@joist-orm\");\nexport const newTestInstance = imp(\"newTestInstance@joist-orm\");\nexport const New = imp(\"t:New@joist-orm\");\nexport const DeepNew = imp(\"t:DeepNew@joist-orm\");\nexport const FactoryOpts = imp(\"t:FactoryOpts@joist-orm\");\nexport const SSAssert = imp(\"assert@superstruct\");\nexport const Zod = imp(\"z@zod\");\nexport const EntityConstructor = imp(\"t:EntityConstructor@joist-orm\");\nexport const MaybeAbstractEntityConstructor = imp(\"t:MaybeAbstractEntityConstructor@joist-orm\");\nexport const deTagId = imp(\"deTagId@joist-orm\");\nexport const toIdOf = imp(\"toIdOf@joist-orm\");\nexport const toJSON = imp(\"toJSON@joist-orm\");\nexport const ReactiveField = imp(\"t:ReactiveField@joist-orm\");\nexport const ReactiveReference = imp(\"t:ReactiveReference@joist-orm\");\nexport const ReactiveManyToMany = imp(\"t:ReactiveManyToMany@joist-orm\");\nexport const ReactiveManyToManyOtherSide = imp(\"t:ReactiveManyToManyOtherSide@joist-orm\");\nexport const hasReactiveManyToManyOtherSide = imp(\"hasReactiveManyToManyOtherSide@joist-orm\");\nexport const updatePartial = imp(\"updatePartial@joist-orm\");\nexport const setRuntimeConfig = imp(\"setRuntimeConfig@joist-orm\");\n"],"mappings":";;;AAEA,MAAa,iBAAA,GAAgBA,QAAAA,IAAAA,CAAI,wBAAwB;AACzD,MAAa,iBAAA,GAAgBA,QAAAA,IAAAA,CAAI,6BAA6B;AAE9D,MAAa,aAAA,GAAYA,QAAAA,IAAAA,CAAI,qBAAqB;AAClD,MAAa,cAAA,GAAaA,QAAAA,IAAAA,CAAI,sBAAsB;AACpD,MAAa,SAAA,GAAQA,QAAAA,IAA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D,MAAa,oBAAA,GAAmBA,QAAAA,IAAAA,CAAI,4BAA4B"}
@@ -18,6 +18,11 @@ declare const EntityMetadata: import("ts-poet").Import;
18
18
  declare const EnumMetadata: import("ts-poet").Import;
19
19
  declare const Lens: import("ts-poet").Import;
20
20
  declare const KeySerde: import("ts-poet").Import;
21
+ declare const Column: import("ts-poet").Import;
22
+ declare const ColumnDescriptors: import("ts-poet").Import;
23
+ declare const SimpleFieldSerde: import("ts-poet").Import;
24
+ declare const PolyComponent: import("ts-poet").Import;
25
+ declare const polymorphicField: import("ts-poet").Import;
21
26
  declare const ManyToOneReference: import("ts-poet").Import;
22
27
  declare const LazyField: import("ts-poet").Import;
23
28
  declare const hasLazyField: import("ts-poet").Import;
@@ -111,5 +116,5 @@ declare const hasReactiveManyToManyOtherSide: import("ts-poet").Import;
111
116
  declare const updatePartial: import("ts-poet").Import;
112
117
  declare const setRuntimeConfig: import("ts-poet").Import;
113
118
  //#endregion
114
- export { BaseEntity, BigIntSerde, BooleanFilter, BooleanGraphQLFilter, Changes, Collection, ConfigApi, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, DeepNew, DeepPartialOrNull, Entity, EntityConstructor, EntityFilter, EntityGraphQLFilter, EntityManager, EntityMetadata, EnumArrayFieldSerde, EnumCollection, EnumFieldSerde, EnumGraphQLFilter, EnumMetadata, FactoryOpts, FieldStatus, FieldsOf, FilterOf, Flavor, GraphQLFilterOf, IdOf, JoistEntityManager, JsonHint, JsonPayload, JsonSerde, KeySerde, LargeCollection, LazyField, Lens, LoadHint, Loaded, ManyToManyCollection, ManyToOneReference, MaybeAbstractEntityConstructor, New, OneToManyCollection, OneToOneReference, OptsOf, OrderBy, PartialOrNull, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PolymorphicKeySerde, PolymorphicReference, PrimitiveSerde, ProjectEntity, ReactiveField, ReactiveManyToMany, ReactiveManyToManyOtherSide, ReactiveReference, ReadOnlyCollection, Reference, RelationsOf, SSAssert, Scope, SuperstructSerde, TaggedId, ToJsonHint, ValueFilter, ValueGraphQLFilter, Zod, ZodSerde, ZonedDateTimeSerde, cannotBeUpdated, cleanStringValue, configureMetadata, deTagId, fail, failNoIdYet, getField, getInstanceData, hasEnumCollection, hasLargeMany, hasLargeManyToMany, hasLazyField, hasMany, hasManyToMany, hasOne, hasOnePolymorphic, hasOneThrough, hasOneToOne, hasReactiveManyToManyOtherSide, hasRecursiveChildren, hasRecursiveM2m, hasRecursiveParents, isEntity, isLoaded, loadLens, mustBeSubType, newChangesProxy, newRequiredLazyFieldRule, newRequiredRule, newScopeFn, newTestInstance, nowUTC, setField, setOpts, setRuntimeConfig, toIdOf, toJSON, updatePartial };
119
+ export { BaseEntity, BigIntSerde, BooleanFilter, BooleanGraphQLFilter, Changes, Collection, Column, ColumnDescriptors, ConfigApi, CustomSerdeAdapter, DateSerde, DecimalToNumberSerde, DeepNew, DeepPartialOrNull, Entity, EntityConstructor, EntityFilter, EntityGraphQLFilter, EntityManager, EntityMetadata, EnumArrayFieldSerde, EnumCollection, EnumFieldSerde, EnumGraphQLFilter, EnumMetadata, FactoryOpts, FieldStatus, FieldsOf, FilterOf, Flavor, GraphQLFilterOf, IdOf, JoistEntityManager, JsonHint, JsonPayload, JsonSerde, KeySerde, LargeCollection, LazyField, Lens, LoadHint, Loaded, ManyToManyCollection, ManyToOneReference, MaybeAbstractEntityConstructor, New, OneToManyCollection, OneToOneReference, OptsOf, OrderBy, PartialOrNull, PlainDateSerde, PlainDateTimeSerde, PlainTimeSerde, PolyComponent, PolymorphicKeySerde, PolymorphicReference, PrimitiveSerde, ProjectEntity, ReactiveField, ReactiveManyToMany, ReactiveManyToManyOtherSide, ReactiveReference, ReadOnlyCollection, Reference, RelationsOf, SSAssert, Scope, SimpleFieldSerde, SuperstructSerde, TaggedId, ToJsonHint, ValueFilter, ValueGraphQLFilter, Zod, ZodSerde, ZonedDateTimeSerde, cannotBeUpdated, cleanStringValue, configureMetadata, deTagId, fail, failNoIdYet, getField, getInstanceData, hasEnumCollection, hasLargeMany, hasLargeManyToMany, hasLazyField, hasMany, hasManyToMany, hasOne, hasOnePolymorphic, hasOneThrough, hasOneToOne, hasReactiveManyToManyOtherSide, hasRecursiveChildren, hasRecursiveM2m, hasRecursiveParents, isEntity, isLoaded, loadLens, mustBeSubType, newChangesProxy, newRequiredLazyFieldRule, newRequiredRule, newScopeFn, newTestInstance, nowUTC, polymorphicField, setField, setOpts, setRuntimeConfig, toIdOf, toJSON, updatePartial };
115
120
  //# sourceMappingURL=symbols.d.cts.map