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

Calculated fields #1539

Merged
merged 14 commits into from
Jul 19, 2024
Merged

Calculated fields #1539

merged 14 commits into from
Jul 19, 2024

Conversation

MarcAstr0
Copy link
Collaborator

@MarcAstr0 MarcAstr0 commented Jul 3, 2024

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

  • 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.
  • Updated documentation.

Checks

  • Project Builds
  • Project passes tests and checks
  • Updated documentation accordingly

@MarcAstr0
Copy link
Collaborator Author

/integration sha=c9dcfc3c4768ff9098f4d1d766f91e7018c85046

Copy link

what-the-diff bot commented Jul 3, 2024

PR Summary

  • Changes in the Package framework-common-helpers

    • A new function createInstanceWithCalculatedProperties was added to enhance read model classes, enabling them to include calculated properties in their responses.
    • Functions to build and process properties maps were also added, assisting in controlling which properties to include in responses.
    • A checker function isPromise was introduced to verify if an object is a promise.
  • Modifications in the Package framework-core

    • The booster-read-models-reader.ts file now incorporates the createInstanceWithCalculatedProperties function. A new function createReadModelInstancesWithCalculatedProperties was included to enhance read model instances with the calculated properties.
    • The search function was modified for optimized performance when calculated fields dependencies exist.
    • A new decorator CalculatedField was introduced in read-model.ts to mark a property as a calculated field with dependencies.
  • Updates in Test Cases

    • New test cases were added to verify the functionality of the createReadModelInstancesWithCalculatedProperties function and the CalculatedField decorator.
    • Existing test cases were updated to accommodate the new dependencies property in the fields metadata.
  • Additions in the Integration Tests

    • A new test case was introduced to test the process of projecting calculated fields in read model query.
  • Changes in the framework-integration-tests Project

    • The CartMyAddress command file was added.
    • The CalculatedField decorator was used in cart-read-model.ts for several methods.
    • A new dependencies property was added to the PropertyMetadata interface to hold the dependencies of the calculated fields.

Copy link
Contributor

github-actions bot commented Jul 3, 2024

⌛ Integration tests are running...

Check their status here 👈

const isArray = part.endsWith('[]')
const key = isArray ? part.slice(0, -2) : part
if (!current[key]) {
current[key] = isArray ? { __isArray: true, __children: {} } : {}

Check warning

Code scanning / CodeQL

Prototype-polluting assignment Medium

This assignment may alter Object.prototype if a malicious '__proto__' string is injected from
library input
.
Copy link
Contributor

github-actions bot commented Jul 3, 2024

❌ Oh no! Integration tests have failed

6 similar comments
Copy link
Contributor

github-actions bot commented Jul 3, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 3, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 3, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 3, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 3, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 4, 2024

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=e815183

Copy link
Contributor

github-actions bot commented Jul 4, 2024

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

github-actions bot commented Jul 4, 2024

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=7d65cb3

Copy link
Contributor

github-actions bot commented Jul 4, 2024

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

github-actions bot commented Jul 4, 2024

❌ Oh no! Integration tests have failed

6 similar comments
Copy link
Contributor

github-actions bot commented Jul 4, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 4, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 4, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 5, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 5, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 5, 2024

❌ Oh no! Integration tests have failed

@MarcAstr0 MarcAstr0 force-pushed the calculated_fields branch from 7d65cb3 to 008414c Compare July 5, 2024 12:16
@MarcAstr0
Copy link
Collaborator Author

/integration sha=008414c64635315ceda16888eaf39c0d73161b9e

Copy link
Contributor

github-actions bot commented Jul 8, 2024

❌ Oh no! Integration tests have failed

2 similar comments
Copy link
Contributor

github-actions bot commented Jul 8, 2024

❌ Oh no! Integration tests have failed

Copy link
Contributor

github-actions bot commented Jul 8, 2024

❌ Oh no! Integration tests have failed

@MarcAstr0
Copy link
Collaborator Author

/integration sha=3b899a6bc06d65be4f1f2bf59f3becb67abe995e

Copy link
Contributor

github-actions bot commented Jul 8, 2024

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

github-actions bot commented Jul 8, 2024

✅ Integration tests have finished successfully!

@MarcAstr0 MarcAstr0 marked this pull request as ready for review July 8, 2024 19:41
@MarcAstr0
Copy link
Collaborator Author

/integration sha=85ea3c15ed9f3acf080593bec19df41e4bff93fe

Copy link
Contributor

github-actions bot commented Jul 8, 2024

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

github-actions bot commented Jul 8, 2024

✅ Integration tests have finished successfully!

@MarcAstr0
Copy link
Collaborator Author

/integration sha=56633030c1307dc0adf1bc187387e69731cbc387

Copy link
Contributor

github-actions bot commented Jul 9, 2024

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

github-actions bot commented Jul 9, 2024

✅ Integration tests have finished successfully!

Copy link
Contributor

@alvaroloes alvaroloes left a comment

Choose a reason for hiding this comment

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

Amazing job! Just a small comment about UX

@MarcAstr0
Copy link
Collaborator Author

/integration sha=2077b2cb598e6b6259ef8e2d1b6756e8cead1f53

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

❌ Oh no! Integration tests have failed

Copy link
Contributor

⌛ Integration tests are running...

Check their status here 👈

Copy link
Contributor

✅ Integration tests have finished successfully!

@MarcAstr0 MarcAstr0 merged commit 177b038 into boostercloud:main Jul 19, 2024
6 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