Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Mar 29, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a rule engine module that enhances configuration management with robust logic for retrieving and prioritizing configuration values across different contexts.
  • Chores
    • Streamlined schema definitions to boost type safety.
    • Updated development tooling, including linting and build configurations, for improved code maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 29, 2025

Walkthrough

This pull request refactors the deployment variable schema for improved readability by streamlining the syntax and adding a new inferred type export. It also introduces several new configuration files: an ESLint configuration file and a TypeScript configuration file, and a new package.json for the rule-engine package. Additionally, new asynchronous functions for retrieving variable values—based on resource, deployment, and environment priorities—are added in a new release generation module.

Changes

File(s) Change Summary
packages/db/src/schema/deployment-variables.ts Refactored the createDeploymentVariableValue schema by streamlining .omit() and .extend() methods, and added a new type export: CreateDeploymentVariableValue.
packages/deployment-variables/eslint.config.js Introduced a new ESLint configuration that imports base settings and custom rules (ignoring dist/** and disabling @typescript-eslint/require-await).
packages/deployment-variables/package.json Added a package manifest for @ctrlplane/rule-engine with metadata, export definitions, scripts, dependencies, and a Prettier configuration.
packages/deployment-variables/src/generate-releases.ts Created new asynchronous functions (getResourceVariable, getDeploymentVariableValue, getVariableSetValue, getValueForResource) for retrieving variable values from the database with a defined fallback order.
packages/deployment-variables/tsconfig.json Introduced a new TypeScript configuration extending an internal base, specifying output directories, incremental builds, and file inclusion/exclusion rules.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant RV as ResourceVariable
    participant DV as DeploymentVariable
    participant VS as VariableSet

    Caller->>RV: getResourceVariable(db, resourceId, key)
    alt Resource variable exists
        RV-->>Caller: value
    else Resource variable missing
        Caller->>DV: getDeploymentVariableValue(db, resourceId, deploymentId, key)
        alt Deployment variable exists
            DV-->>Caller: value
        else Deployment variable missing
            Caller->>VS: getVariableSetValue(db, environmentId, key)
            VS-->>Caller: value or null
        end
    end
Loading

Possibly related PRs

  • fix: Create deployment endpoints #296: Updates to the deployment schema and type definitions in that PR overlap with the changes introduced here, particularly regarding the new CreateDeploymentVariableValue type and schema modifications.

Suggested reviewers

  • jsbroks

Poem

I'm a rabbit in the code garden, so sly,
Hopping through schema changes that catch my eye.
Lines refactored with a swift little bound,
New types and functions, neat and sound.
With ESLint and TS config in the mix,
I nibble bugs away with clever tricks.
Happy hops to the code that clicks!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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: 1

🧹 Nitpick comments (3)
packages/deployment-variables/src/generate-releases.ts (3)

11-21: Consider returning only the needed property.

getResourceVariable currently returns the entire resource-variable row, though only the value column is used downstream. Returning a more specific structure (e.g., just the value) could simplify your data flow and make the function’s intent clearer.

-  .then(takeFirstOrNull);
+  .then((row) => {
+    const result = takeFirstOrNull(row);
+    return result ? result.value : null;
+  });

31-73: Enhance efficiency when fetching deployment variable values.

The current approach sorts all values, then iterates and runs a query for each to match a resource. This can become inefficient at scale. Consider a single, more selective query (e.g., a joined query) to match the resource and resource selector at once, reducing repeated lookups.


126-146: Examine fallback strategy and incorporate default handling.

When none of the three checks yields a value, this function returns null. If a fallback or default is expected, consider returning a more descriptive result or throwing an error to clearly indicate an unassigned key, based on your business logic.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e5b8f4 and 7318312.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • packages/db/src/schema/deployment-variables.ts (1 hunks)
  • packages/deployment-variables/eslint.config.js (1 hunks)
  • packages/deployment-variables/package.json (1 hunks)
  • packages/deployment-variables/src/generate-releases.ts (1 hunks)
  • packages/deployment-variables/tsconfig.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • packages/db/src/schema/deployment-variables.ts
  • packages/deployment-variables/src/generate-releases.ts
🧬 Code Definitions (1)
packages/deployment-variables/src/generate-releases.ts (1)
packages/db/src/schema/deployment-variables.ts (1)
  • deploymentVariableValue (57-76)
🪛 GitHub Actions: CI
packages/deployment-variables/package.json

[error] 1-1: Failed to add workspace '@ctrlplane/rule-engine', it already exists at 'packages/rule-engine/package.json'.

🔇 Additional comments (5)
packages/deployment-variables/eslint.config.js (1)

1-13: LGTM! Clear and well-structured ESLint configuration.

The configuration properly extends the base config and adds specific customizations. Good job disabling the @typescript-eslint/require-await rule if your code needs to use async functions that don't necessarily contain await statements.

packages/deployment-variables/tsconfig.json (1)

1-11: Well-structured TypeScript configuration

The TypeScript configuration extends the base configuration appropriately and includes all necessary settings for proper compilation. The inclusion of incremental builds and a specific build info file location are good optimizations for development.

packages/db/src/schema/deployment-variables.ts (1)

84-88: Excellent code refactoring for improved readability

The code has been streamlined by simplifying the chained method calls and adding a useful type export. The new CreateDeploymentVariableValue type will improve type safety when working with the schema across the codebase.

packages/deployment-variables/src/generate-releases.ts (2)

1-2: Imports look good.

The imports from @ctrlplane/db and @ctrlplane/db/schema are clear and match the usage throughout this file.


82-106: Validate handling of multiple environment variable set entries.

getVariableSetValue retrieves only the very first matching value (ordered by JSON ascending). Ensure that returning just one entry (due to .limit(1)) is sufficient for your business requirements, especially if multiple variable sets could define the same key. If the environment can truly have only one match, consider adding a uniqueness constraint for clarity and maintainability.

Comment on lines +1 to +37
{
"name": "@ctrlplane/rule-engine",
"private": true,
"version": "0.1.0",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./dist/index.js"
}
},
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"test": "vitest",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@ctrlplane/db": "workspace:*",
"@ctrlplane/validators": "workspace:*",
"ts-is-present": "catalog:"
},
"devDependencies": {
"@ctrlplane/eslint-config": "workspace:*",
"@ctrlplane/prettier-config": "workspace:*",
"@ctrlplane/tsconfig": "workspace:*",
"@types/node": "catalog:node22",
"eslint": "catalog:",
"prettier": "catalog:",
"typescript": "catalog:"
},
"prettier": "@ctrlplane/prettier-config"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Critical naming conflict with an existing package

The pipeline is failing because there's already a package named @ctrlplane/rule-engine at packages/rule-engine/package.json. This package needs to be renamed to something else, likely @ctrlplane/deployment-variables to match the directory name.

-  "name": "@ctrlplane/rule-engine",
+  "name": "@ctrlplane/deployment-variables",

🏁 Script executed:

#!/bin/bash
# Check if there's already a package at packages/rule-engine
if [ -f "packages/rule-engine/package.json" ]; then
  echo "Verification: Found existing package at packages/rule-engine/package.json"
  grep -n "\"name\":" packages/rule-engine/package.json
fi

# Check if the directory name matches other package patterns
echo "Current directory structure suggests the package should be named:"
basename "$(dirname "$(pwd)/packages/deployment-variables")"

Length of output: 552


Critical Naming Conflict: Rename Package

The package in packages/deployment-variables/package.json is currently named "@ctrlplane/rule-engine", which conflicts with the existing package at packages/rule-engine/package.json that already uses that name. To resolve the pipeline failure and maintain naming consistency with the directory structure, please update the package name accordingly:

  • File to update: packages/deployment-variables/package.json
  • Action required: Change the package name from "@ctrlplane/rule-engine" to "@ctrlplane/deployment-variables".
-  "name": "@ctrlplane/rule-engine",
+  "name": "@ctrlplane/deployment-variables",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"name": "@ctrlplane/rule-engine",
"private": true,
"version": "0.1.0",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./dist/index.js"
}
},
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"test": "vitest",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@ctrlplane/db": "workspace:*",
"@ctrlplane/validators": "workspace:*",
"ts-is-present": "catalog:"
},
"devDependencies": {
"@ctrlplane/eslint-config": "workspace:*",
"@ctrlplane/prettier-config": "workspace:*",
"@ctrlplane/tsconfig": "workspace:*",
"@types/node": "catalog:node22",
"eslint": "catalog:",
"prettier": "catalog:",
"typescript": "catalog:"
},
"prettier": "@ctrlplane/prettier-config"
}
{
"name": "@ctrlplane/deployment-variables",
"private": true,
"version": "0.1.0",
"type": "module",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./dist/index.js"
}
},
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"test": "vitest",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@ctrlplane/db": "workspace:*",
"@ctrlplane/validators": "workspace:*",
"ts-is-present": "catalog:"
},
"devDependencies": {
"@ctrlplane/eslint-config": "workspace:*",
"@ctrlplane/prettier-config": "workspace:*",
"@ctrlplane/tsconfig": "workspace:*",
"@types/node": "catalog:node22",
"eslint": "catalog:",
"prettier": "catalog:",
"typescript": "catalog:"
},
"prettier": "@ctrlplane/prettier-config"
}
🧰 Tools
🪛 GitHub Actions: CI

[error] 1-1: Failed to add workspace '@ctrlplane/rule-engine', it already exists at 'packages/rule-engine/package.json'.

@adityachoudhari26 adityachoudhari26 deleted the init-value-selection branch May 5, 2025 19:49
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