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

fix: properly align all types of class properties (action, inline types, statics, ...) #349

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

stockbal
Copy link
Contributor

@stockbal stockbal commented Oct 6, 2024

Fixes property alignment in generated class functions

Before

  • Inline types (with --inlineDeclarations structured option)

    export function _CompanyAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
      return class Company extends Base {
            address?: {
          place?: string | null,
          zip?: string | null,
          info?: {
            a?: string | null,
            a_a?: {
              a?: string | null,
            } | null,
          } | null,
        } | null;
      };
    }
  • Bound Actions

    export function _CompanyAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
      return class Company extends Base {
          declare static readonly actions: {
            changeLeader: {
    // positional
    (leaderName: string | null): any
    // named
    ({leaderName}: {leaderName?: string | null}): any, 
    // metadata (do not use)
    __parameters: {leaderName?: string | null}, __returns: any, kind: 'action'}
          }
      };
    }

After

  • with --inlineDeclarations structured

    export function _CompanyAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
      return class Company extends Base {
        declare ID?: __.Key<string>;
        declare name?: string | null;
        declare address?: {
          place?: string | null,
          zip?: string | null,
          info?: {
            a?: string | null,
            a_a?: {
              a?: string | null,
            } | null,
          } | null,
        } | null;
        static readonly kind: 'entity' | 'type' | 'aspect' = 'entity';
        declare static readonly keys: __.KeysOf<Company>
        declare static readonly actions: {
          changeLeader:  {
            // positional
            (leaderName: string | null): any
            // named
            ({leaderName}: {leaderName?: string | null}): any
            // metadata (do not use)
            __parameters: {leaderName?: string | null}, __returns: any
            kind: 'action'
          }
        }
      };
    }
  • with --inlineDeclarations flat

    export function _CompanyAspect<TBase extends new (...args: any[]) => object>(Base: TBase) {
      return class Company extends Base {
        declare ID?: __.Key<string>
        declare name?: string | null
        declare address_place?: string | null
        declare address_zip?: string | null
        declare address_info_a?: string | null
        declare address_info_a_a_a?: string | null
        // inline enums
        static readonly kind: 'entity' | 'type' | 'aspect' = 'entity';
        declare static readonly keys: __.KeysOf<Company>
        declare static readonly actions: {
          changeLeader:  {
            // positional
            (leaderName: string | null): any
            // named
            ({leaderName}: {leaderName?: string | null}): any
            // metadata (do not use)
            __parameters: {leaderName?: string | null}, __returns: any
            kind: 'action'
          }
        }
      };
    }

@daogrady daogrady self-requested a review October 14, 2024 04:16
Copy link
Contributor

@daogrady daogrady left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, thanks! 😃

@daogrady daogrady merged commit db69843 into cap-js:main Oct 14, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants