Skip to content

[Feature]: TS Type generation#199

Merged
kfirstri merged 16 commits intomainfrom
basic-types-support
Feb 8, 2026
Merged

[Feature]: TS Type generation#199
kfirstri merged 16 commits intomainfrom
basic-types-support

Conversation

@kfirstri
Copy link
Collaborator

@kfirstri kfirstri commented Feb 5, 2026

Note

Description

This PR adds a new base44 types generate command that generates TypeScript declaration files for Base44 projects. The command reads entities, functions, and agents from the project configuration and creates a type-safe base44/.types/types.d.ts file with interfaces for entity schemas and registries for all resources. This enables autocomplete and type safety when using the @base44/sdk in TypeScript projects, improving developer experience with IDE support for project-specific schemas.

Related Issue

Depends on base44/javascript-sdk#117

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Changes Made

Core Type Generation Module (src/core/types/)

  • Added generator.ts: Converts entity JSON schemas to TypeScript interfaces using json-schema-to-typescript, handles nested objects, arrays, enums, and Base44-specific property types
  • Added update-project.ts: Automatically updates tsconfig.json to include generated types in the include array
  • Implemented registry generation for EntityTypeRegistry, FunctionNameRegistry, and AgentNameRegistry

CLI Command (src/cli/commands/types/)

  • Added types parent command with generate subcommand (currently hidden from help menu)
  • Command supports custom output directory via -o, --output flag
  • Provides user-friendly output with resource counts and file paths

Dependencies & Configuration

  • Added json-schema-to-typescript for schema-to-interface conversion
  • Added common-tags for clean template string formatting
  • Added corresponding TypeScript type definitions (@types/json-schema, @types/common-tags)
  • Added constants TYPES_OUTPUT_SUBDIR and TYPES_FILENAME to src/core/consts.ts
  • Added getTypesOutputPath() helper to src/core/config.ts

Error Handling

  • Added TypeGenerationError to the error hierarchy in src/core/errors.ts
  • Provides actionable hints for type generation failures

Schema Updates

  • Removed deprecated property types (binary, file, regex) from entity schema

Templates & Testing

  • Updated .gitignore templates to exclude generated .types/ directory
  • Added comprehensive test suite in tests/cli/types_generate.spec.ts
  • Created test fixture with-types-resources with entities, functions, and agents
  • Extended CLITestkit with test override support for app config mocking

Reliability Improvements

  • Increased version check timeout from 500ms to 1000ms to reduce flakiness

Documentation

  • Updated AGENTS.md with complete architecture documentation for the types module

Testing

  • I have tested these changes locally
  • I have added/updated tests as needed
  • All tests pass (bun test)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have updated AGENTS.md if I made architectural changes

Additional Notes

Generated Output Structure:
The command generates a single declaration file that augments the @base44/sdk module with project-specific types:

  • Entity interfaces in PascalCase (e.g., user_profileUserProfile)
  • Type registries for autocomplete in SDK methods (e.g., sdk.entity.create('user', ...))
  • Handles empty projects gracefully with placeholder comments

Command Usage:

base44 types generate  # Generates base44/.types/types.d.ts + updates tsconfig.json

Module Architecture:

src/core/types/
├── generator.ts       # Entity-to-TypeScript interface conversion & registry generation
├── update-project.ts  # Automatic tsconfig.json updates
└── index.ts           # Barrel exports

The types command is currently hidden from the help menu while the feature undergoes final integration testing with the Base44 JavaScript SDK.


🤖 Generated by Claude | 2026-02-08 15:10 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/cli@0.0.28-pr.199.af7e13e

Prefer not to change any import paths? Install using npm alias so your code still imports base44:

npm i "base44@npm:@base44-preview/cli@0.0.28-pr.199.af7e13e"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "base44": "npm:@base44-preview/cli@0.0.28-pr.199.af7e13e"
  }
}

Preview published to npm registry — try new features instantly!

@claude
Copy link

claude bot commented Feb 5, 2026

Posting inline comments on PR #199...

@claude
Copy link

claude bot commented Feb 5, 2026

Code review

Found 1 issue that needs attention:

Issue: Incorrect command in generated file comments

Files affected:

  • src/core/types/template.ts (lines 20 and 28)

Problem:
The auto-generated comments in both HEADER and EMPTY_TEMPLATE constants say:

// Regenerate with: base44 types

However, the correct command is:

// Regenerate with: base44 types generate

Why this matters:
The types command is a parent command with a generate subcommand (see program.ts:241-243). Running just base44 types will show help text, not regenerate the types file. Users following the comment instruction would get confused.

Suggested fix:
Update both occurrences to include the full command: base44 types generate


Review scope: Checked for bugs and CLAUDE.md compliance.

@kfirstri
Copy link
Collaborator Author

kfirstri commented Feb 5, 2026

Gap i see - the "Task" returned from the sdk doesn't not have the predefined fields like "is_sample", "id", "created_by"....

@kfirstri kfirstri moved this from Backlog to In progress in CLI Development Feb 8, 2026
@kfirstri kfirstri moved this from In progress to In review in CLI Development Feb 8, 2026
@kfirstri kfirstri merged commit c4f8c9d into main Feb 8, 2026
6 checks passed
@kfirstri kfirstri deleted the basic-types-support branch February 8, 2026 15:04
@github-project-automation github-project-automation bot moved this from In review to Done in CLI Development Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant