diff --git a/composer.json b/composer.json index 0b18c89..cf44b82 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "kiwilan/typescriptable-laravel", "description": "PHP package for Laravel to type Eloquent models, routes, Spatie Settings with autogenerated TypeScript. If you want to use some helpers with Inertia, you can install associated NPM package.", - "version": "1.12.01", + "version": "1.12.02", "keywords": [ "kiwilan", "laravel", @@ -32,11 +32,10 @@ "spatie/laravel-package-tools": "^1.16.3" }, "require-dev": { - "doctrine/dbal": "^3.5", "laravel/pint": "^1.0", - "nunomaduro/collision": "^7.6.0", + "nunomaduro/collision": "^7.6.0 || ^8.0", "larastan/larastan": "^2.8.0", - "orchestra/testbench": "^8.5", + "orchestra/testbench": "^8.5 || ^9.0", "pestphp/pest": "^2.8.1", "pestphp/pest-plugin-laravel": "*", "phpstan/extension-installer": "^1.1", diff --git a/src/Typed/Database/DatabaseScan.php b/src/Typed/Database/DatabaseScan.php index e1a2e34..6f0c35e 100644 --- a/src/Typed/Database/DatabaseScan.php +++ b/src/Typed/Database/DatabaseScan.php @@ -20,7 +20,13 @@ protected function __construct( public static function make(): self { $type = Schema::getConnection()->getDriverName(); - $schemaTables = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); + + $schemaTables = []; + if (intval(app()->version()) >= 11) { + $schemaTables = Schema::getTableListing(); + } else { + $schemaTables = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); // @phpstan-ignore-line + } $items = []; foreach ($schemaTables as $table) { diff --git a/src/Typed/Database/MysqlColumn.php b/src/Typed/Database/MysqlColumn.php index 8e9649f..8998380 100644 --- a/src/Typed/Database/MysqlColumn.php +++ b/src/Typed/Database/MysqlColumn.php @@ -2,8 +2,6 @@ namespace Kiwilan\Typescriptable\Typed\Database; -use Doctrine\DBAL\Types\Types; - class MysqlColumn implements IColumn { public const TYPE = 'mysql'; @@ -48,39 +46,39 @@ public static function make(array|object $data, string $table, string $driver): public static function typeToPhp(string $formatType): string { return match ($formatType) { - 'char' => Types::STRING, - 'varchar' => Types::STRING, - 'tinytext' => Types::STRING, - 'text' => Types::STRING, - 'mediumtext' => Types::STRING, - 'longtext' => Types::STRING, - 'tinyblob' => Types::STRING, - 'blob' => Types::STRING, - 'mediumblob' => Types::STRING, - 'longblob' => Types::STRING, - 'enum' => Types::STRING, - 'set' => Types::STRING, - 'binary' => Types::STRING, - 'varbinary' => Types::STRING, - 'bit' => Types::STRING, - 'date' => Types::STRING, - 'datetime' => Types::STRING, - 'timestamp' => Types::STRING, - 'time' => Types::STRING, - 'year' => Types::STRING, + 'char' => 'string', + 'varchar' => 'string', + 'tinytext' => 'string', + 'text' => 'string', + 'mediumtext' => 'string', + 'longtext' => 'string', + 'tinyblob' => 'string', + 'blob' => 'string', + 'mediumblob' => 'string', + 'longblob' => 'string', + 'enum' => 'string', + 'set' => 'string', + 'binary' => 'string', + 'varbinary' => 'string', + 'bit' => 'string', + 'date' => 'string', + 'datetime' => 'string', + 'timestamp' => 'string', + 'time' => 'string', + 'year' => 'string', 'int' => 'int', 'tinyint' => 'int', 'smallint' => 'int', 'mediumint' => 'int', 'bigint' => 'int', - 'float' => Types::FLOAT, - 'double' => Types::FLOAT, - 'decimal' => Types::FLOAT, - 'boolean' => Types::BOOLEAN, - 'json' => Types::JSON, - 'jsonb' => Types::JSON, - 'uuid' => Types::STRING, - default => Types::STRING, + 'float' => 'float', + 'double' => 'float', + 'decimal' => 'float', + 'boolean' => 'boolean', + 'json' => 'json', + 'jsonb' => 'json', + 'uuid' => 'string', + default => 'string', }; } } diff --git a/src/Typed/Database/PostgreColumn.php b/src/Typed/Database/PostgreColumn.php index 2ab9d3a..9958ab3 100644 --- a/src/Typed/Database/PostgreColumn.php +++ b/src/Typed/Database/PostgreColumn.php @@ -2,8 +2,6 @@ namespace Kiwilan\Typescriptable\Typed\Database; -use Doctrine\DBAL\Types\Types; - class PostgreColumn implements IColumn { public const TYPE = 'pgsql'; @@ -40,49 +38,49 @@ public static function make(array|object $data, string $table, string $driver): public static function typeToPhp(string $formatType): string { return match ($formatType) { - 'bigint' => Types::BIGINT, - 'bigserial' => Types::BIGINT, - 'bit' => Types::STRING, - 'bit varying' => Types::STRING, - 'boolean' => Types::BOOLEAN, - 'box' => Types::STRING, - 'bytea' => Types::BINARY, - 'character' => Types::STRING, - 'character varying' => Types::STRING, - 'cidr' => Types::STRING, - 'circle' => Types::STRING, - 'date' => Types::STRING, - 'double precision' => Types::FLOAT, - 'inet' => Types::STRING, + 'bigint' => 'bigint', + 'bigserial' => 'bigint', + 'bit' => 'string', + 'bit varying' => 'string', + 'boolean' => 'boolean', + 'box' => 'string', + 'bytea' => 'binary', + 'character' => 'string', + 'character varying' => 'string', + 'cidr' => 'string', + 'circle' => 'string', + 'date' => 'string', + 'double precision' => 'float', + 'inet' => 'string', 'integer' => 'int', - 'interval' => Types::STRING, - 'json' => Types::JSON, - 'jsonb' => Types::JSON, - 'line' => Types::STRING, - 'lseg' => Types::STRING, - 'macaddr' => Types::STRING, - 'money' => Types::STRING, - 'numeric' => Types::FLOAT, - 'path' => Types::STRING, - 'point' => Types::STRING, - 'polygon' => Types::STRING, - 'real' => Types::FLOAT, - 'smallint' => Types::SMALLINT, - 'smallserial' => Types::SMALLINT, + 'interval' => 'string', + 'json' => 'json', + 'jsonb' => 'json', + 'line' => 'string', + 'lseg' => 'string', + 'macaddr' => 'string', + 'money' => 'string', + 'numeric' => 'float', + 'path' => 'string', + 'point' => 'string', + 'polygon' => 'string', + 'real' => 'float', + 'smallint' => 'smallint', + 'smallserial' => 'smallint', 'serial' => 'int', - 'text' => Types::TEXT, - 'time' => Types::STRING, - 'time without time zone' => Types::STRING, - 'time with time zone' => Types::STRING, - 'timestamp' => Types::STRING, - 'timestamp without time zone' => Types::STRING, - 'timestamp with time zone' => Types::STRING, - 'tsquery' => Types::STRING, - 'tsvector' => Types::STRING, - 'txid_snapshot' => Types::STRING, - 'uuid' => Types::GUID, - 'xml' => Types::STRING, - default => Types::STRING, + 'text' => 'text', + 'time' => 'string', + 'time without time zone' => 'string', + 'time with time zone' => 'string', + 'timestamp' => 'string', + 'timestamp without time zone' => 'string', + 'timestamp with time zone' => 'string', + 'tsquery' => 'string', + 'tsvector' => 'string', + 'txid_snapshot' => 'string', + 'uuid' => 'guid', + 'xml' => 'string', + default => 'string', }; } } diff --git a/src/Typed/Database/SqlServerColumn.php b/src/Typed/Database/SqlServerColumn.php index 1655eb9..fbb3934 100644 --- a/src/Typed/Database/SqlServerColumn.php +++ b/src/Typed/Database/SqlServerColumn.php @@ -2,8 +2,6 @@ namespace Kiwilan\Typescriptable\Typed\Database; -use Doctrine\DBAL\Types\Types; - class SqlServerColumn implements IColumn { public const TYPE = 'sqlsrv'; @@ -39,35 +37,35 @@ public static function typeToPhp(string $formatType): string { return match ($formatType) { 'bigint' => 'int', - 'binary' => Types::BINARY, - 'bit' => Types::BOOLEAN, - 'char' => Types::STRING, - 'date' => Types::STRING, - Types::STRING => Types::STRING, - 'datetime2' => Types::STRING, - 'datetimeoffset' => Types::STRING, - 'decimal' => Types::FLOAT, - 'float' => Types::FLOAT, - 'image' => Types::BINARY, + 'binary' => 'binary', + 'bit' => 'boolean', + 'char' => 'string', + 'date' => 'string', + 'string' => 'string', + 'datetime2' => 'string', + 'datetimeoffset' => 'string', + 'decimal' => 'float', + 'float' => 'float', + 'image' => 'binary', 'int' => 'int', - 'money' => Types::FLOAT, - 'nchar' => Types::STRING, - 'ntext' => Types::STRING, - 'numeric' => Types::FLOAT, - 'nvarchar' => Types::STRING, - 'real' => Types::FLOAT, - 'smalldatetime' => Types::STRING, + 'money' => 'float', + 'nchar' => 'string', + 'ntext' => 'string', + 'numeric' => 'float', + 'nvarchar' => 'string', + 'real' => 'float', + 'smalldatetime' => 'string', 'smallint' => 'int', - 'smallmoney' => Types::FLOAT, - 'text' => Types::STRING, - 'time' => Types::STRING, - 'timestamp' => Types::BINARY, + 'smallmoney' => 'float', + 'text' => 'string', + 'time' => 'string', + 'timestamp' => 'binary', 'tinyint' => 'int', - 'uniqueidentifier' => Types::GUID, - 'varbinary' => Types::BINARY, - 'varchar' => Types::STRING, - 'xml' => Types::STRING, - default => Types::STRING, + 'uniqueidentifier' => 'guid', + 'varbinary' => 'binary', + 'varchar' => 'string', + 'xml' => 'string', + default => 'string', }; } } diff --git a/src/Typed/Database/SqliteColumn.php b/src/Typed/Database/SqliteColumn.php index 270c8dc..edd90d7 100644 --- a/src/Typed/Database/SqliteColumn.php +++ b/src/Typed/Database/SqliteColumn.php @@ -2,8 +2,6 @@ namespace Kiwilan\Typescriptable\Typed\Database; -use Doctrine\DBAL\Types\Types; - class SqliteColumn implements IColumn { public const TYPE = 'sqlite'; @@ -57,28 +55,28 @@ public static function typeToPhp(string $formatType): string 'UNSIGNED BIG INT' => 'int', 'INT2' => 'int', 'INT8' => 'int', - 'CHARACTER(20)' => Types::STRING, - 'VARCHAR(255)' => Types::STRING, - 'VARYING CHARACTER(255)' => Types::STRING, - 'NCHAR(55)' => Types::STRING, - 'NATIVE CHARACTER' => Types::STRING, - 'NVARCHAR(100)' => Types::STRING, - 'TEXT' => Types::STRING, - 'CLOB' => Types::STRING, - 'BLOB' => Types::STRING, - 'REAL' => Types::FLOAT, - 'DOUBLE' => Types::FLOAT, - 'DOUBLE PRECISION' => Types::FLOAT, - 'FLOAT' => Types::FLOAT, - 'NUMERIC' => Types::FLOAT, - 'DECIMAL(10,5)' => Types::FLOAT, - 'BOOLEAN' => Types::BOOLEAN, - 'DATE' => Types::STRING, - 'DATETIME' => Types::STRING, - 'TIMESTAMP' => Types::STRING, - 'TIME' => Types::TIME_MUTABLE, - 'BLOB' => Types::BINARY, - default => Types::STRING, + 'CHARACTER(20)' => 'string', + 'VARCHAR(255)' => 'string', + 'VARYING CHARACTER(255)' => 'string', + 'NCHAR(55)' => 'string', + 'NATIVE CHARACTER' => 'string', + 'NVARCHAR(100)' => 'string', + 'TEXT' => 'string', + 'CLOB' => 'string', + 'BLOB' => 'string', + 'REAL' => 'float', + 'DOUBLE' => 'float', + 'DOUBLE PRECISION' => 'float', + 'FLOAT' => 'float', + 'NUMERIC' => 'float', + 'DECIMAL(10,5)' => 'float', + 'BOOLEAN' => 'boolean', + 'DATE' => 'string', + 'DATETIME' => 'string', + 'TIMESTAMP' => 'string', + 'TIME' => 'time', + 'BLOB' => 'binary', + default => 'string', }; } } diff --git a/src/Typed/Database/Table.php b/src/Typed/Database/Table.php index c4cfaf0..bfbe7d0 100644 --- a/src/Typed/Database/Table.php +++ b/src/Typed/Database/Table.php @@ -69,7 +69,12 @@ private function setColumns(): array throw new \Exception("Database driver not supported: {$this->driver}"); } - $schemaTables = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); + $schemaTables = []; + if (intval(app()->version()) >= 11) { + $schemaTables = Schema::getTableListing(); + } else { + $schemaTables = Schema::getConnection()->getDoctrineSchemaManager()->listTableNames(); // @phpstan-ignore-line + } if (! in_array($this->name, $schemaTables)) { return [];