boostercloud / booster

Booster Framework
https://www.boosterframework.com
Apache License 2.0
416 stars 86 forks source link

Calculated fields #1539

Closed MarcAstr0 closed 2 months ago

MarcAstr0 commented 3 months ago

Description

Due to the changes introduced in version 2.11.0, this PR introduces the @CalculatedField decorator for read model fields, which are calculated using getters using other properties of the read model. e.g.,

@ReadModel({
  authorize: 'all',
})
export class PersonReadModel {
  public constructor(
    readonly id: UUID,
    readonly firstName: string,
    readonly lastName: string
  ) {}

  @CalculatedField(['firstName', 'lastName'])
  public get fullName(): Promise<string> {
    return Promise.resolve(`${this.firstName} ${this.lastName}`)
  }
}

This decorator receives a list of the read model's properties as an input parameter. The calculated field uses these properties to calculate its value. The decorator ensures that these properties are fetched from the database so that the calculated field is calculated correctly, even if the user did not explicitly request these dependencies.

Changes

Checks

github-actions[bot] commented 2 months ago

:x: Oh no! Integration tests have failed

github-actions[bot] commented 2 months ago

:hourglass: Integration tests are running...

Check their status here πŸ‘ˆ

github-actions[bot] commented 2 months ago

:white_check_mark: Integration tests have finished successfully!