Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationships constants in generators #26075

Closed
wants to merge 5 commits into from
Closed

Conversation

Tcharl
Copy link
Contributor

@Tcharl Tcharl commented May 8, 2024

The goal being to be able to find in one click within an IDE all the relationship usage within the entire jhipster codebase.

Do you agree with the design? Is so, I'll continue on the entire codebase


Please make sure the below checklist is followed for Pull Requests.

When you are still working on the PR, consider converting it to Draft (below reviewers) and adding skip-ci label, you can still see CI build result at your branch.

generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
generators/entity/support/relationships.ts Outdated Show resolved Hide resolved
@mshima
Copy link
Member

mshima commented May 8, 2024

Many generators are written in typescript now.
In my opinion using variables now is not as useful as it was before.
It creates too much overhead.

import { fooType } from '../../jdl/jhipster/index.js';

const { A_CONSTANT } = fooType;

value === A_CONSTANT;

Instead of:

value === 'aConstant'; // validated by typescript (undefined | 'aConstant' | 'anotherConstant')

@Tcharl
Copy link
Contributor Author

Tcharl commented May 8, 2024

Agreed that it needs more lines, still, using constants instead of plain strings permits:

  • Folding in IDE ('find usage'), which helps newcomers to better understand the codebase
  • Prevents Typo
  • Ease the migration to proper typescript (constant will be an enum of the class)
  • Ensures proper modules acyclic graph (because we're referencing a constant that is in a 'support' package of another module)
  • Ensures type safety on methods signatures
  • Allows loops over constants of the consts record
  • And for sure a bit more (I hope that typescript will soon implements sealed class like java does)

So IMHO, the benefits overcomes the drawbacks.

@Tcharl Tcharl changed the title proof of concept regarding relationships constants in generator Relationships constants in generators May 8, 2024
@mraible mraible requested a review from mshima June 20, 2024 21:21
@mshima
Copy link
Member

mshima commented Jun 21, 2024

I don’t think we should go this way.

import { RelationshipTypes, ONE_TO_ONE } from '../../entity/support/index.js';
RelationshipTypes[ONE_TO_ONE])

Instead of typescript verified.

'one-to-one'

It’s much more complicated.

@Tcharl Tcharl closed this Aug 28, 2024
@mraible mraible added this to the 8.7.1 milestone Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants