Files
klz-cables.com/.pnpm-store/v10/files/64/4ccdb008752d2654339d6fd833d5c6c8ea54456dccdd3812e80ba0cd81820690cb1ce708b3cb55aa07ea61312069255ea3e72ab7a02d097b61294c79e09de2
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

37 lines
1.5 KiB
Plaintext

import { APIError } from 'payload';
import toSnakeCase from 'to-snake-case';
/**
* Used to name database enums and tables
* Returns the table or enum name for a given entity
*/ export const createTableName = ({ adapter, config: { name, slug }, config, parentTableName, prefix = '', target = 'dbName', throwValidationError = false, versions = false, versionsCustomName = false })=>{
let customNameDefinition = config[target];
let defaultTableName = `${prefix}${toSnakeCase(name ?? slug)}`;
if (versions) {
defaultTableName = `_${defaultTableName}${adapter.versionsSuffix}`;
}
let customTableNameResult;
if (!customNameDefinition && target === 'enumName') {
customNameDefinition = config['dbName'];
}
if (customNameDefinition) {
customTableNameResult = typeof customNameDefinition === 'function' ? customNameDefinition({
tableName: parentTableName
}) : customNameDefinition;
if (versionsCustomName) {
customTableNameResult = `_${customTableNameResult}${adapter.versionsSuffix}`;
}
}
const result = customTableNameResult || defaultTableName;
adapter.tableNameMap.set(defaultTableName, result);
if (!throwValidationError) {
return result;
}
if (result.length > 63) {
throw new APIError(`Exceeded max identifier length for table or enum name of 63 characters. Invalid name: ${result}.
Tip: You can use the dbName property to reduce the table name length.
`);
}
return result;
};
//# sourceMappingURL=createTableName.js.map