Skip to content

feat(sdk): improve configurable_prop types #16698

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

TheBestMoshe
Copy link
Collaborator

@TheBestMoshe TheBestMoshe commented May 16, 2025

WHY

Many possible types were missing and/or not correctly defined.

Summary by CodeRabbit

  • New Features
    • Expanded support for a wider range of configurable component properties, including arrays and specialized service types.
    • Added support for labeled string options in configurable properties.
  • Improvements
    • Enhanced type safety and expressiveness for component configuration options.
    • Improved consistency in property definitions and formatting.

Copy link

vercel bot commented May 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview May 16, 2025 7:55pm
pipedream-docs ⬜️ Ignored (Inspect) May 16, 2025 7:55pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) May 16, 2025 7:55pm

Copy link
Contributor

coderabbitai bot commented May 16, 2025

"""

Walkthrough

The update enhances the SDK's type definitions for configurable component properties by introducing new property types, including array variants and specialized service types. It refines existing types, expands the union and conditional types to cover new cases, and improves type safety by updating generic defaults and adding explicit options and defaults for string properties.

Changes

File(s) Change Summary
packages/sdk/src/shared/component.ts Added new types for string options, array and specialized property types; extended union and conditional types; updated generics and formatting for stronger typing and consistency.
packages/connect-react/CHANGELOG.md Added changelog entry for version 1.0.3 documenting improvement to ConfigurableProp type.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component
    participant SDK

    User->>Component: Define configurable properties (with new types)
    Component->>SDK: Pass properties with type annotations
    SDK-->>Component: Validate and infer types (including arrays, services)
    Component-->>User: Expose strongly-typed configuration interface
Loading

Poem

In the warren of types, new options appear,
Arrays and services, all crystal clear.
Strings with labels, numbers that dance,
Discord and HTTP now get their chance.
A hop, a skip, type safety anew—
The SDK grows stronger, for me and for you!
🐇✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a6dd5f4 and 961ffed.

📒 Files selected for processing (1)
  • packages/connect-react/CHANGELOG.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/connect-react/CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Lint Code Base

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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 2

🧹 Nitpick comments (1)
packages/sdk/src/shared/component.ts (1)

167-204: Conditional chain in PropValue is becoming brittle

PropValue now contains 20+ nested ternaries.
While it compiles, the growing depth:

  • hurts readability and maintenance,
  • complicates debugging when a new type is appended in the wrong spot,
  • risks hitting the TS recursion limit.

A more maintainable pattern is a lookup map plus an indexed access:

type PropValueMap = {
  alert: never;
  any: any; // eslint-disable-line @typescript-eslint/no-explicit-any
  app: { authProvisionId: string };
  boolean: boolean;
  "boolean[]": boolean[];
  integer: number;
  "integer[]": number[];
  number: number;
  "number[]": number[];
  object: object;
  string: string;
  "string[]": string[];
  "$.discord.channel": string;
  "$.discord.channel[]": string[];
  "$.interface.http": unknown;
  "$.interface.timer": unknown;
  "$.service.db": unknown;
  datastore: unknown;
  http_request: unknown;
  sql: unknown;
};

export type PropValue<T extends keyof PropValueMap> = PropValueMap[T];

This flattens complexity, makes compiler errors point directly at the mapping entry, and eases future additions (one line per new type).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between ae1b6f8 and 8063b1b.

📒 Files selected for processing (1)
  • packages/sdk/src/shared/component.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint Code Base

Comment on lines 98 to 119
export type ConfigurablePropNumber = BaseConfigurableProp & {
type: "number";
min?: number;
max?: number;
} & Defaultable<number>;
export type ConfigurablePropNumberArray = BaseConfigurableProp & {
type: "number[]";
} & Defaultable<number>;
export type ConfigurablePropIntegerArray = BaseConfigurableProp & {
type: "integer[]";
} & Defaultable<number>;
export type ConfigurablePropBooleanArray = BaseConfigurableProp & {
type: "boolean[]";
} & Defaultable<boolean>;
export type ConfigurablePropDiscordChannel = BaseConfigurableProp & {
type: "$.discord.channel";
[key: string]: unknown;
} & Defaultable<string>;
export type ConfigurablePropDiscordChannelArray = BaseConfigurableProp & {
type: "$.discord.channel[]";
[key: string]: unknown;
} & Defaultable<string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Array prop defaults / options currently accept scalar values

The four definitions below inherit Defaultable<scalar> and therefore expose the wrong surface in editors and generated JSON schemas:

  • ConfigurablePropNumberArray
  • ConfigurablePropIntegerArray
  • ConfigurablePropBooleanArray
  • ConfigurablePropDiscordChannelArray

Either:

  1. Create type DefaultableArray<T> = { default?: T[]; options?: T[] } and use that, or
  2. Inline the correct fields as shown in the previous comment.

This minor refactor removes an entire class of silent runtime bugs while keeping the public API intact.

🤖 Prompt for AI Agents
In packages/sdk/src/shared/component.ts between lines 98 and 119, the array
types ConfigurablePropNumberArray, ConfigurablePropIntegerArray,
ConfigurablePropBooleanArray, and ConfigurablePropDiscordChannelArray
incorrectly use Defaultable with scalar types, causing defaults and options to
accept scalar values instead of arrays. To fix this, define a new type
DefaultableArray<T> with default and options as optional arrays of T, then
replace Defaultable<T> with DefaultableArray<T> in these array type definitions
to ensure defaults and options are arrays, preventing runtime bugs.

Comment on lines +57 to +58
type Defaultable<T> = { default?: T; options?: T[] };

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Defaultable is too restrictive for “array-of-X” property kinds

Defaultable<T> hard-codes options?: T[].
When you reuse it for array property kinds ("number[]", "integer[]", "boolean[]", etc.) you end up with:

default?: number;        // should be number[]
options?: number[];      // should be number[]

Consequently default and PropValue<"number[]"> become incompatible and the compiler will not prevent the error because the mismatch sits in different structural types (prop definition vs. configured value).

Consider introducing a dedicated helper for array props or inlining default / options:

-export type ConfigurablePropNumberArray = BaseConfigurableProp & {
-  type: "number[]";
-} & Defaultable<number>;
+export type ConfigurablePropNumberArray = BaseConfigurableProp & {
+  type: "number[]";
+  default?: number[];
+  options?: number[];
+};

Same adjustment is required for ConfigurablePropIntegerArray, ConfigurablePropBooleanArray, and ConfigurablePropDiscordChannelArray.
Failing to do so will allow mis-typed defaults to slip into published schema and break user tooling at runtime.

📝 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
type Defaultable<T> = { default?: T; options?: T[] };
export type ConfigurablePropNumberArray = BaseConfigurableProp & {
type: "number[]";
default?: number[];
options?: number[];
};
🤖 Prompt for AI Agents
In packages/sdk/src/shared/component.ts around lines 57 to 58, the
Defaultable<T> type is too restrictive because it defines options as T[] and
default as T, which causes type mismatches for array property kinds like
"number[]". To fix this, create a separate helper type specifically for array
properties where both default and options are arrays of T (e.g., default?: T[];
options?: T[][] or appropriate array types), and update
ConfigurablePropIntegerArray, ConfigurablePropBooleanArray, and
ConfigurablePropDiscordChannelArray accordingly to use this new helper, ensuring
type compatibility and preventing mis-typed defaults.

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

♻️ Duplicate comments (3)
packages/sdk/src/shared/component.ts (3)

57-57: Type is correctly defined, but consider the implications for array properties

The Defaultable<T> type is defined correctly, but as noted in previous reviews, this type becomes problematic when applied to array properties.


98-103: ⚠️ Potential issue

Array prop defaults still accept scalar values

The ConfigurablePropIntegerArray and ConfigurablePropBooleanArray types inherit Defaultable<number> and Defaultable<boolean> respectively, which means their default property accepts scalar values (number/boolean) instead of arrays (number[]/boolean[]).

This should be fixed by either:

  1. Creating a specific type for array defaults:
+type DefaultableArray<T> = { default?: T[]; options?: T[] };
 export type ConfigurablePropIntegerArray = BaseConfigurableProp & {
   type: "integer[]";
-} & Defaultable<number>;
+} & DefaultableArray<number>;
  1. Or by explicitly specifying the correct field types:
 export type ConfigurablePropIntegerArray = BaseConfigurableProp & {
   type: "integer[]";
-} & Defaultable<number>;
+  default?: number[];
+  options?: number[];
 };

Apply the same solution to ConfigurablePropBooleanArray.


104-111: ⚠️ Potential issue

Discord channel array type has incorrect default type

Similar to the integer and boolean arrays, the ConfigurablePropDiscordChannelArray type inherits Defaultable<string>, which means it accepts a scalar string as a default value instead of a string array.

 export type ConfigurablePropDiscordChannelArray = BaseConfigurableProp & {
   type: "$.discord.channel[]";
   [key: string]: unknown;
-} & Defaultable<string>;
+  default?: string[];
+  options?: string[];
 };
🧹 Nitpick comments (2)
packages/sdk/src/shared/component.ts (2)

113-133: Good addition of specialized service and interface types

The new specialized property types for interfaces and services are well-structured and appropriately use [key: string]: unknown to allow for additional properties that might be specific to each type.

Consider adding JSDoc comments to document what additional properties each specialized type might accept for better developer guidance.


157-189: Comprehensive property value type mapping

The expanded PropValue<T> conditional type correctly maps all property types to their corresponding TypeScript types, which ensures type safety when accessing property values.

The deeply nested ternary structure could become hard to maintain as more types are added. Consider an alternative approach using a type lookup table:

type PropValueMap = {
  "alert": never;
  "any": any;
  "app": { authProvisionId: string };
  "boolean": boolean;
  "boolean[]": boolean[];
  "integer": number;
  "integer[]": number[];
  "object": object;
  "string": string;
  "string[]": string[];
  "$.discord.channel": string;
  "$.discord.channel[]": string[];
  "$.interface.http": unknown;
  "$.interface.timer": unknown;
  "$.service.db": unknown;
  "datastore": unknown;
  "http_request": unknown;
  "sql": unknown;
};

export type PropValue<T extends ConfigurableProp["type"]> = T extends keyof PropValueMap 
  ? PropValueMap[T] 
  : never;

This approach is more maintainable and scales better when adding new types.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 8063b1b and a6dd5f4.

📒 Files selected for processing (1)
  • packages/sdk/src/shared/component.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test
  • GitHub Check: pnpm publish
  • GitHub Check: Lint Code Base
🔇 Additional comments (8)
packages/sdk/src/shared/component.ts (8)

59-61: Good addition for more flexible string option definitions

The new string option types provide more flexibility by allowing either plain strings or objects with labels and values. This will improve developer experience by enabling descriptive labels for dropdown options.


75-77: Boolean type now properly supports defaults and options

Adding Defaultable<boolean> to the ConfigurablePropBoolean type is a good improvement that ensures boolean properties can have default values and predefined options.


86-91: Good explicit type definitions for string properties

Instead of using Defaultable<string>, explicitly defining default and options with the new StringPropOption[] type provides better flexibility for string properties with labeled options.


92-97: Correct array typing for string arrays

The ConfigurablePropStringArray type correctly uses string[] for the default value type, which matches the property type. This prevents potential type errors at runtime.


135-153: Complete union type including all new property types

The ConfigurableProp union is properly updated to include all the new property types, ensuring they're recognized throughout the codebase.


191-193: Minor formatting improvement

The addition of a semicolon after the property signature is a minor formatting improvement for consistency.


196-196: Improved type safety with better generic defaults

Changing the default generic parameter from any to ConfigurableProps improves type safety by ensuring a sensible default rather than allowing any type.


205-207: Consistent improvement in generic defaults

Similar to V1Component, this change improves type safety by using ConfigurableProps as the default generic parameter.

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