Skip to content

Commit

Permalink
Merge pull request #58 from kiwilan/develop
Browse files Browse the repository at this point in the history
v1.12.02
  • Loading branch information
ewilan-riviere authored Mar 16, 2024
2 parents eb71e78 + 2656c7a commit e18f47c
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 135 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ jobs:
- name: Create dotenv file
run: cp .env.example .env

- name: Execute tests
run: vendor/bin/pest

- name: Setup node
uses: actions/setup-node@v4
with:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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.0",
"version": "1.12.02",
"keywords": [
"kiwilan",
"laravel",
Expand All @@ -26,17 +26,17 @@
],
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.5",
"illuminate/contracts": "^9.0 || ^10.0 || ^11.0",
"illuminate/database": "^9.0 || ^10.0 || ^11.0",
"illuminate/support": "^9.0 || ^10.0 || ^11.0",
"spatie/laravel-package-tools": "^1.14.0"
"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",
Expand Down
8 changes: 7 additions & 1 deletion src/Typed/Database/DatabaseScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 28 in src/Typed/Database/DatabaseScan.php

View workflow job for this annotation

GitHub Actions / phpstan

No error to ignore is reported on line 28.

Check failure on line 28 in src/Typed/Database/DatabaseScan.php

View workflow job for this annotation

GitHub Actions / phpstan

No error to ignore is reported on line 28.
}

$items = [];
foreach ($schemaTables as $table) {
Expand Down
58 changes: 28 additions & 30 deletions src/Typed/Database/MysqlColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Kiwilan\Typescriptable\Typed\Database;

use Doctrine\DBAL\Types\Types;

class MysqlColumn implements IColumn
{
public const TYPE = 'mysql';
Expand Down Expand Up @@ -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',
};
}
}
84 changes: 41 additions & 43 deletions src/Typed/Database/PostgreColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Kiwilan\Typescriptable\Typed\Database;

use Doctrine\DBAL\Types\Types;

class PostgreColumn implements IColumn
{
public const TYPE = 'pgsql';
Expand Down Expand Up @@ -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',
};
}
}
54 changes: 26 additions & 28 deletions src/Typed/Database/SqlServerColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Kiwilan\Typescriptable\Typed\Database;

use Doctrine\DBAL\Types\Types;

class SqlServerColumn implements IColumn
{
public const TYPE = 'sqlsrv';
Expand Down Expand Up @@ -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',
};
}
}
46 changes: 22 additions & 24 deletions src/Typed/Database/SqliteColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Kiwilan\Typescriptable\Typed\Database;

use Doctrine\DBAL\Types\Types;

class SqliteColumn implements IColumn
{
public const TYPE = 'sqlite';
Expand Down Expand Up @@ -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',
};
}
}
7 changes: 6 additions & 1 deletion src/Typed/Database/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 76 in src/Typed/Database/Table.php

View workflow job for this annotation

GitHub Actions / phpstan

No error to ignore is reported on line 76.

Check failure on line 76 in src/Typed/Database/Table.php

View workflow job for this annotation

GitHub Actions / phpstan

No error to ignore is reported on line 76.
}

if (! in_array($this->name, $schemaTables)) {
return [];
Expand Down

0 comments on commit e18f47c

Please sign in to comment.