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

Enforce conventions around entity file order #934

Open
stephenh opened this issue Jan 6, 2024 · 0 comments
Open

Enforce conventions around entity file order #934

stephenh opened this issue Jan 6, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@stephenh
Copy link
Collaborator

stephenh commented Jan 6, 2024

Ideally we like to see entities follow a consistent pattern of:

  • The entity class declaration
    • any custom relations, i.e. readonly numberOfBooks = hasPersistedAsyncPropety
    • the constructor
    • methods/async methods with business logic
    • getters/setters
  • Validation rules
    • Simple validation rules i.e. config.addRule(a => ...)
    • Reactive validation rules i.e. config.addRule("firstName", a => ...)
  • Hooks in the order that Joist runs them
    • beforeCreate
    • beforeUpdate
    • beforeFlush
    • etc.

Approaches

The most traditional approach for this would be an eslint rule(s).

An alternative would be the config API at boot-time what "phase" it's in it, and throw an error if a previous phase is called. However we'd needed exceptions for helper methods (like our internal addCollaborationUtils that adds multiple hooks) and also wouldn't get order of fields/cstr/getters within the class.

@stephenh stephenh added the enhancement New feature or request label Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant