Skip to content

refactor: add typed interfaces for SQL/REST API integrations #79

Closed

Description

@larryro

Problem

The Doc<'integrations'> type from Convex doesn't properly capture optional/discriminated fields like sqlConnectionConfig and sqlOperations at the type level. This leads to widespread any usage and type assertions throughout the integration-related code:

const sqlConnectionConfig = (integration as any).sqlConnectionConfig;
const integrationType = (integration as any).type || 'rest_api';

Affected Files

  • convex/agent_tools/integrations/execute_batch_integration_internal.ts
  • convex/workflow/actions/integration/helpers/execute_sql_integration.ts
  • convex/workflow/actions/integration/integration_action.ts

Proposed Solution

  1. Create typed interfaces for SQL and REST API integrations:
interface SqlIntegration extends Doc<'integrations'> {
  type: 'sql';
  sqlConnectionConfig: { engine: 'mssql' | 'postgres' | 'mysql'; ... };
  sqlOperations: Array<{ name: string; query: string; ... }>;
}

interface RestApiIntegration extends Doc<'integrations'> {
  type: 'rest_api';
  connector: { code: string; operations: Array<...>; ... };
}
  1. Create type guards to narrow integration types:
function isSqlIntegration(integration: Doc<'integrations'>): integration is SqlIntegration {
  return integration.type === 'sql' && 'sqlConnectionConfig' in integration;
}
  1. Update all consumers to use type guards instead of any casts.

Context

This issue was identified during PR #76 code review. The current pattern works but violates TypeScript best practices and the project's coding guidelines which prohibit type casting and any usage.

🤖 Generated with Claude Code

Activity

  1. added 3 commits that reference this issue on Jan 5, 2026
    8e36be2
    0b86237
    22002c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions