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

v0.1.0 2026-01-12 22:30 UTC

This package is auto-updated.

Last update: 2026-01-12 22:30:26 UTC


README

Latest Version on Packagist Total Downloads GitHub Tests Action Status

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.