-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add base44 types command for TypeScript type generation
#102
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Generates TypeScript types from local entity schemas: - Entity interfaces with system fields (id, created_date, updated_date) - CreateInput/UpdateInput types for CRUD operations - Filter types for query operations - Typed SDK client interface matching @base44/sdk API Usage: base44 generate [-o <dir>] [--entities-only]
- base44 generate → base44 types - Update generated file header comments
- Document the types command and its options - Add TypeScript type generation section with usage examples - Update project structure to show generated types directory
Contributor
🚀 Package Preview Available!Install this PR's preview build with npm: npm i @base44-preview/cli@0.0.15-pr.102.ec2ad29Prefer not to change any import paths? Install using npm alias so your code still imports npm i "base44@npm:@base44-preview/cli@0.0.15-pr.102.ec2ad29"Or add it to your {
"dependencies": {
"base44": "npm:@base44-preview/cli@0.0.15-pr.102.ec2ad29"
}
}
Preview published to npm registry — try new features instantly! |
base44 generate command for TypeScript type generationbase44 types command for TypeScript type generation
Consistent naming with the `base44 types` command.
- Add support for `integer` type (maps to `number`) - Add support for `null` type - Add support for union types: `["string", "null"]` → `string | null` - Support mixed enum values (string, number, boolean, null) - Add `format` field support in schema - Fix inline object generation for nested properties
Replace in-house JSON Schema → TypeScript conversion with the battle-tested json-schema-to-typescript library. Benefits: - Full JSON Schema draft-07 support - Handles $ref, allOf, anyOf, oneOf - Proper JSDoc generation from descriptions - Better handling of complex nested types
- Output types.d.ts for Node.js (declare module '@base44/sdk') - Output types.deno.d.ts for Deno (declare module 'npm:@base44/sdk') - Default output directory changed to base44/ (alongside entity schemas) - User code remains unchanged - types are injected via module augmentation - Add --node-only flag to skip Deno types generation
Document the full product specification including: - Command usage and options - Generated file structure for Node.js and Deno - Setup instructions for tsconfig.json and deno.json - User experience walkthrough with examples - JSON Schema to TypeScript type mapping reference - SDK requirements for module augmentation support - Recommended workflow for type generation
Contributor
|
Wokring on my own branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #101
Overview
This PR introduces the
base44 typescommand - a TypeScript type generator that reads local entity schemas and produces fully-typed interfaces for use with the@base44/sdk.Motivation
When building applications with Base44, developers define data models (entities) as JSON schema files:
However, when using these entities in TypeScript code via the SDK, there's no type safety:
This PR solves that problem by generating TypeScript types from the schema files.
Solution
Command
Generated Output
For each entity, the command generates:
{Entity}{Entity}CreateInput{Entity}UpdateInput{Entity}FilterPlus SDK integration types:
EntityHandler<T>- Generic CRUD interface matching SDK methodsTypedEntities- Map of all entities to their handlersTypedBase44Client- Drop-in typed wrapper for the SDK clientExample Output
Input:
base44/entities/task.jsonc{ "name": "Task", "type": "object", "properties": { "title": { "type": "string", "description": "Task title" }, "completed": { "type": "boolean", "default": false }, "priority": { "type": "string", "enum": ["low", "medium", "high"] } }, "required": ["title"] }Output:
src/base44/entities.tsOutput:
src/base44/client.tsUser Experience
Before (no types)
After (with generated types)
Implementation Details
Architecture
Supported Field Types
stringstringnumbernumberbooleanbooleanarrayT[](with typed items)objectRecord<string, unknown>enum'a' | 'b' | 'c'Design Decisions
@base44/sdkmethod signatures exactlyTesting
Documentation
Future Improvements