{"version":3,"file":"attribute-naming.mjs","sources":["../../src/metadata/attribute-naming.ts"],"sourcesContent":["import { snakeCase } from 'lodash';\n\nimport { identifiers } from '../utils/identifiers';\n\n/**\n * The rules that turn an attribute's logical name into the physical database\n * identifiers it maps to. This is the only place those rules live: the metadata\n * loader (`metadata.ts`, `relations.ts`) uses them when registering models, and\n * callers that need to predict a name for an attribute that is not registered\n * yet — e.g. the Content-Type Builder computing the *new* side of a rename\n * migration before the server reloads — use them too, so the two can never\n * drift apart.\n *\n * Components, dynamic zones and media do not derive a physical identifier from\n * the attribute name: the name itself is stored as a value in the link table's\n * `field` column (`identifiers.FIELD_COLUMN`).\n */\nexport const attributeNaming = {\n  /**\n   * Column on the model's own table for a scalar attribute.\n   */\n  columnName(attributeName: string): string {\n    return identifiers.getColumnName(snakeCase(attributeName));\n  },\n\n  /**\n   * Column on the model's own table for a relation stored as a join column\n   * (`<attribute>_id`, i.e. `useJoinTable: false` or an owning x-to-one).\n   */\n  joinColumnName(attributeName: string): string {\n    return identifiers.getJoinColumnAttributeIdName(snakeCase(attributeName));\n  },\n\n  /**\n   * Join/link table for a relation owned by `attributeName` on the model whose\n   * table is `tableName`.\n   */\n  joinTableName(tableName: string, attributeName: string): string {\n    return identifiers.getJoinTableName(snakeCase(tableName), snakeCase(attributeName));\n  },\n};\n\nexport type AttributeNaming = typeof attributeNaming;\n"],"names":["attributeNaming","columnName","attributeName","identifiers","getColumnName","snakeCase","joinColumnName","getJoinColumnAttributeIdName","joinTableName","tableName","getJoinTableName"],"mappings":";;;AAIA;;;;;;;;;;;;UAaaA,eAAAA,GAAkB;AAC7B;;AAEC,MACDC,YAAWC,aAAqB,EAAA;QAC9B,OAAOC,WAAAA,CAAYC,aAAa,CAACC,SAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AAC7C,IAAA,CAAA;AAEA;;;AAGC,MACDI,gBAAeJ,aAAqB,EAAA;QAClC,OAAOC,WAAAA,CAAYI,4BAA4B,CAACF,SAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AAC5D,IAAA,CAAA;AAEA;;;MAIAM,aAAAA,CAAAA,CAAcC,SAAiB,EAAEP,aAAqB,EAAA;AACpD,QAAA,OAAOC,WAAAA,CAAYO,gBAAgB,CAACL,SAAAA,CAAUI,YAAYJ,SAAAA,CAAUH,aAAAA,CAAAA,CAAAA;AACtE,IAAA;AACF;;;;"}