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

chore(dsl): Enforce types #16375

Closed
wants to merge 5 commits into from
Closed

chore(dsl): Enforce types #16375

wants to merge 5 commits into from

Conversation

AndesKrrrrrrrrrrr
Copy link
Member

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr commented Oct 11, 2024

Make mappings be typed, not arbitrary keys

Summary by CodeRabbit

  • New Features

    • Introduced new types for improved clarity in ingress configurations, including IngressType and IngressMapping.
  • Improvements

    • Enhanced type assertions for ingress configurations to ensure better structure and adherence to defined types.
    • Updated type signatures across various interfaces for consistency and clarity in environmental context.

These changes aim to improve the reliability and maintainability of the application while enhancing user experience through clearer configurations.

Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.73%. Comparing base (420313d) to head (40e5061).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16375   +/-   ##
=======================================
  Coverage   36.73%   36.73%           
=======================================
  Files        6809     6809           
  Lines      141086   141086           
  Branches    40224    40224           
=======================================
  Hits        51825    51825           
  Misses      89261    89261           
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.42% <ø> (ø)
application-template-api-modules 27.88% <ø> (-0.02%) ⬇️
application-ui-shell 21.35% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 420313d...40e5061. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs b848792 🔗

4 Total Test Services: 0 Failed, 4 Passed
➡️ Test Sessions change in coverage: 8 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.86s 1 no change Link
application-system-api 0 0 0 120 2 3m 30.9s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 13.2s 1 no change Link
application-ui-shell 0 0 0 74 0 30.21s 1 no change Link

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr marked this pull request as ready for review October 15, 2024 17:33
@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr requested a review from a team as a code owner October 15, 2024 17:33
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes involve updates to TypeScript type definitions and method signatures across several files to improve type safety and clarity. The serviceSetup function in web.ts now includes a type assertion for the ingress configuration. The ServiceBuilder class in dsl.ts has been modified to use a new IngressMapping type. Additionally, type signatures in charts.ts and input-types.ts have been altered for consistency, including renaming parameters and introducing new types like IngressType.

Changes

File Change Summary
apps/web/infra/web.ts Added type assertion for ingress configuration in serviceSetup: ingress({...} as Ingress).
infra/src/dsl/dsl.ts Updated ServiceBuilder class to use IngressMapping for ingress property and method signature: ingress(ingress: IngressMapping).
infra/src/dsl/types/charts.ts Renamed mapped type parameter from name to env in EnvironmentServices type: export type EnvironmentServices = { [env in OpsEnv]: ServiceBuilder<any>[] }.
infra/src/dsl/types/input-types.ts Renamed index signatures from idx to env in multiple type definitions, added IngressType and IngressMapping, updated ServiceDefinition to use IngressMapping.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WebService
    participant ServiceBuilder
    participant Ingress

    Client->>WebService: Request service setup
    WebService->>ServiceBuilder: Initialize with ingress configuration
    ServiceBuilder->>Ingress: Validate ingress mapping
    Ingress-->>ServiceBuilder: Return validated ingress
    ServiceBuilder-->>WebService: Return service setup
    WebService-->>Client: Respond with service setup
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (7)
infra/src/dsl/types/charts.ts (1)

39-39: Improved clarity in EnvironmentServices type declaration

The renaming of the mapped type parameter from name to env enhances the clarity and expressiveness of the DSL syntax. This change makes the type declaration more self-explanatory, as it now clearly indicates that the keys represent environments (OpsEnv).

Consider applying similar naming improvements to other type declarations in this file for consistency, such as the EnvironmentConfigs type on line 41. For example:

export type EnvironmentConfigs = { [envName in OpsEnvName]: EnvironmentConfig }

This would maintain a consistent naming convention throughout the file.

apps/web/infra/web.ts (2)

1-1: Approved: Type assertion improves type safety

The addition of the Ingress type import and the type assertion for the ingress configuration enhances type safety, which aligns with the PR objective. This change follows TypeScript best practices and improves code maintainability.

Consider using a type annotation instead of a type assertion for better type safety:

primary: {
  // ... other properties
} satisfies Ingress

This approach allows TypeScript to verify that the object conforms to the Ingress type, rather than forcing it to be treated as that type.

Also applies to: 53-53


Line range hint 1-72: Overall structure and practices are well-implemented

The file demonstrates good practices for infrastructure-as-code:

  1. It uses a custom DSL for service configuration, which promotes consistency and reusability.
  2. The configuration covers essential aspects like environment variables, secrets, ingress, health checks, and resource limits.
  3. TypeScript is used effectively to improve type safety in the infrastructure setup.

While this file doesn't contain direct NextJS code, it sets up the infrastructure that could support a NextJS application. The configuration allows for environment-specific settings, which is a good practice for managing different deployment environments.

Consider documenting the purpose and usage of this infrastructure setup, either in this file or in a separate README, to help other developers understand how it relates to the NextJS application it supports.

infra/src/dsl/types/input-types.ts (3)

109-110: Enhanced type safety with new IngressType and IngressMapping

The introduction of IngressType and IngressMapping types improves the DSL's expressiveness and type safety for Kubernetes ingress resources. This change allows for more precise and self-documenting ingress configurations.

Consider adding a brief comment explaining the purpose and usage of these new types to further improve the DSL's documentation.


138-138: Enhanced clarity in Ingress interface

The changes in the Ingress interface improve semantic clarity and maintain consistency with previous modifications:

  1. Changing [name in OpsEnv] to [env in OpsEnv] in the host property better represents the environment-specific nature of the configurations.
  2. Updating extraAnnotations to use [env in OpsEnv] and [annotation: string] provides more clarity about the structure and purpose of the annotations.

These changes enhance the readability and maintainability of the DSL.

Consider adding a brief comment explaining the purpose of extraAnnotations to further improve the DSL's documentation.

Also applies to: 142-144


Line range hint 21-234: Overall improvements in DSL clarity and type safety

The changes in this file significantly enhance the DSL's clarity, type safety, and expressiveness:

  1. Consistent use of env instead of idx or name in index signatures improves semantic clarity.
  2. Introduction of IngressType and IngressMapping types provides better structure for ingress configurations.
  3. Updates to various interfaces and types (PostgresInfo, RedisInfo, Ingress, ExtraValues) maintain consistency and improve readability.

These modifications align well with Kubernetes and Helm concepts, making the DSL more robust and easier to use.

To further improve the DSL:

  1. Consider adding brief comments explaining the purpose and usage of new types and complex properties.
  2. Create or update documentation that outlines how to use this DSL to create complex Helm values, especially focusing on the new ingress configuration structure.
  3. If not already present, consider adding examples in the repository that demonstrate how to use these types to define services and their associated resources.
infra/src/dsl/dsl.ts (1)

Line range hint 1-569: Improved type safety enhances DSL clarity

The changes to enforce typing for the ingress method significantly improve the clarity of the DSL by making the expected structure of ingress configurations explicit. This enhancement maintains the DSL's expressiveness while ensuring better integration with Kubernetes resources.

However, to fully meet the coding guidelines for this directory, consider adding documentation on how to use this DSL to create complex Helm values, particularly focusing on the ingress configuration.

Consider adding a code comment or JSDoc above the ingress method to explain its usage and provide an example of a valid IngressMapping object. This would help developers understand how to use this method to create complex Helm values for ingress configurations.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 420313d and 40e5061.

📒 Files selected for processing (4)
  • apps/web/infra/web.ts (2 hunks)
  • infra/src/dsl/dsl.ts (3 hunks)
  • infra/src/dsl/types/charts.ts (1 hunks)
  • infra/src/dsl/types/input-types.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/web/infra/web.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
infra/src/dsl/dsl.ts (1)

Pattern infra/src/dsl/**/*: "Confirm that the code adheres to the following:

  • The clarity and expressiveness of the DSL syntax.
  • Integration with Helm charts and Kubernetes resources.
  • Documentation on how to use the DSL to create complex Helm values."
infra/src/dsl/types/charts.ts (1)

Pattern infra/src/dsl/**/*: "Confirm that the code adheres to the following:

  • The clarity and expressiveness of the DSL syntax.
  • Integration with Helm charts and Kubernetes resources.
  • Documentation on how to use the DSL to create complex Helm values."
infra/src/dsl/types/input-types.ts (1)

Pattern infra/src/dsl/**/*: "Confirm that the code adheres to the following:

  • The clarity and expressiveness of the DSL syntax.
  • Integration with Helm charts and Kubernetes resources.
  • Documentation on how to use the DSL to create complex Helm values."
🔇 Additional comments (6)
infra/src/dsl/types/input-types.ts (4)

21-21: Improved semantic clarity in PostgresInfo type

The change from [idx in OpsEnv] to [env in OpsEnv] enhances the readability and self-documentation of the code. It clearly indicates that the keys represent different environments, which aligns well with the DSL's focus on infrastructure and deployment.


38-38: Consistent naming in RedisInfo type

The change from [idx in OpsEnv] to [env in OpsEnv] in the RedisInfo type is consistent with the previous change in PostgresInfo. This consistency improves the overall readability and maintainability of the DSL.


117-117: Improved type safety in ServiceDefinition

The change from { [name: string]: Ingress } to IngressMapping for the ingress property enhances type safety and provides a more structured approach to defining ingress configurations. This improvement aligns well with Kubernetes resource definitions and makes the DSL more robust.


234-234: Consistent naming in ExtraValues type

The change from [idx in OpsEnv] to [env in OpsEnv] in the ExtraValues type maintains consistency with previous modifications. This change enhances the readability of the DSL by explicitly indicating that the keys represent different environments.

infra/src/dsl/dsl.ts (2)

20-20: LGTM: Import of IngressMapping type

The addition of the IngressMapping import aligns well with the PR objective of enforcing types for mappings. This change enhances type safety for ingress configurations.


465-465: LGTM: Updated ingress method signature

The change to use IngressMapping instead of a generic object type enhances type safety and aligns with the PR objective. This update enforces proper typing for ingress configurations.

To ensure this change doesn't break existing code, please run the following script to check for any incompatible usages of the ingress method:

@AndesKrrrrrrrrrrr
Copy link
Member Author

Merging into #16405

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.

1 participant