kanel icon indicating copy to clipboard operation
kanel copied to clipboard

Make identifier aliasing optional

Open alecmev opened this issue 1 month ago • 1 comments

I found a couple of mentions of the intention of making branding optional, like https://github.com/kristiandupont/kanel/issues/433 and https://github.com/kristiandupont/kanel/discussions/444. It doesn't look like it happened yet, but supplying a custom generateIdentifierType is easy enough:

{
  // ...
  generateIdentifierType: (column, details, config) => {
    const name = kanel.escapeIdentifier(
      pascalCase(details.name) + pascalCase(column.name),
    );

    const configWithoutGenerateIdentifierType = { ...config };
    delete configWithoutGenerateIdentifierType.generateIdentifierType;

    const innerType = kanel.resolveType(
      column,
      details,
      configWithoutGenerateIdentifierType,
    );

    return {
      declarationType: 'typeDeclaration',
      name,
      exportAs: 'named',
      typeDefinition: [
        typeof innerType === 'string' ? innerType : innerType.name,
      ],
      typeImports: typeof innerType === 'string' ? [] : innerType.typeImports,
      comment: [`Identifier type for ${details.schemaName}.${details.name}`],
    };
  },
}

However, I would also like to take this a step further and drop identifier aliasing altogether, so that instead of this:

export type UsersId = string;
export default interface UsersTable {
  id: ColumnType<UsersId, UsersId | undefined, UsersId>;
}

It's just this:

export default interface UsersTable {
  id: ColumnType<string, string | undefined, string>;
}

Type-wise this doesn't get in the way, so this is a low-priority request, of course, but it would be nice to get rid of *Id entries in code completion tooltips. This can probably be accomplished with a plugin, but the number of edge cases feels intimidating.

alecmev avatar Jun 29 '24 13:06 alecmev