michael4d45 / effect-schema-generator
Generate TypeScript interfaces and Effect schemas from PHP Spatie Data classes
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/michael4d45/effect-schema-generator
Requires
- php: ^8.3
- laravel/framework: ^11.0|^12.0
- laravel/surveyor: ^0.1
- nikic/php-parser: ^5.4
- phpdocumentor/reflection-docblock: ^5.3
- spatie/laravel-data: ^4.0
Requires (Dev)
- carthage-software/mago: ^1.0.3
- michael4d45/coverage-treemap: ^1.0.0
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.0
README
Generate TypeScript interfaces and Effect schemas from PHP Spatie Data classes. This package bridges your PHP domain models to your TypeScript frontend contracts by generating AST-based representations and transforming them into valid TypeScript code.
Installation
You can install the package via composer:
composer require michael4d45/effect-schema-generator
You can publish the config file with:
php artisan vendor:publish --tag="effect-schema-config"
Usage
Define your Spatie Data classes as usual:
namespace App\Data; use Spatie\LaravelData\Data; class UserData extends Data { public function __construct( public int $id, public string $name, public string $email, ) {} }
Then run the generator command:
php artisan effect-schema:transform
This will generate TypeScript interfaces and Effect schemas in your configured output directory (defaults to resources/ts/schemas).
Commands
php artisan effect-schema:transform # Generate schemas php artisan effect-schema:transform --dry-run # Preview output
Features
- AST-based generation: Robust transformation from PHP to TypeScript.
- Spatie Data support: Deep integration with
spatie/laravel-data. - Effect Schema: Generates not just interfaces, but runtime-validatable Effect schemas.
- Configurable Transformers: Easily extend the generator with custom type mappings.
- PHPDoc Parsing: Uses PHPDoc annotations to refine or override types.
Configuration
See config/effect-schema.php for all available options, including:
paths: Directories to scan for Data classes.transformers: Custom type transformation logic.output_directory: Where to save the generated TypeScript files.
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.