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
Add the CalculatedField decorator to the framework-core package, which stores the calculated fields and their dependencies in the read model's metadata.
Modify the search method in the BoosterReadModelsReader class so it handles calculated fields accordingly.
Add necessary helper methods for working with the calculated fields and instantiating the read model class.
Fix broken code in the cli package due to updated Node types.
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.,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
CalculatedField
decorator to theframework-core
package, which stores the calculated fields and their dependencies in the read model's metadata.search
method in theBoosterReadModelsReader
class so it handles calculated fields accordingly.cli
package due to updated Node types.Checks