Skip to content
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

Draft: add typescript generated check #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/check-typescript-generated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check Typescript Generated

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3.1'
extensions: intl, zip
- run: composer install
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
- run: npm ci
- run: composer generate-typescript
- run: cat resources/js/types/models.ts
- run: npm run lint:fix
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v17
id: verify-changed-files
with:
fail-if-changed: true
fail-message: 'The models.ts file is not up to date. Please run `composer generate-typescript` locally and commit the changes.'
files: |
resources/js/types/models.ts
11 changes: 11 additions & 0 deletions app/Models/Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Notifications\DatabaseNotification;

class Notification extends DatabaseNotification
{
}
11 changes: 11 additions & 0 deletions app/Models/Token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Laravel\Passport\Token as PassportToken;

class Token extends PassportToken
{
}
10 changes: 10 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Jetstream\HasProfilePhoto;
Expand Down Expand Up @@ -93,4 +95,12 @@ public function organizations(): BelongsToMany
->withTimestamps()
->as('membership');
}

/**
* @return MorphMany<Notification>
*/
public function notifications(): MorphMany
{
return $this->morphMany(Notification::class, 'notifiable')->latest();
}
}
3 changes: 3 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Providers;

use App\Models\Organization;
use App\Models\Token;
use App\Policies\OrganizationPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Laravel\Jetstream\Jetstream;
Expand Down Expand Up @@ -47,5 +48,7 @@ public function boot(): void

// use passport scopes for jetstream token permissions
Jetstream::permissions(Passport::scopeIds());

Passport::useTokenModel(Token::class);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@php ./vendor/bin/phpstan analyse --memory-limit=2G --configuration=phpstan.neon"
],
"generate-typescript": [
"@php artisan model:typer > ./resources/js/types/models.ts"
"@php artisan model:typer > ./resources/js/types/models.ts || true"
],
"ptest": [
"@php artisan test --parallel --colors=always --stop-on-failure"
Expand Down
23 changes: 23 additions & 0 deletions resources/js/types/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface Membership {
updated_at: string | null;
}

export interface Notification {
// relations
notifiable: Notification;
}

export interface Organization {
// columns
id: string;
Expand Down Expand Up @@ -106,6 +111,22 @@ export interface TimeEntry {
task: Task;
}

export interface Token {
// columns
id: string;
user_id: string | null;
client_id: string;
name: string | null;
scopes: string[] | null;
revoked: boolean;
created_at: string | null;
updated_at: string | null;
expires_at: string | null;
// relations
client: Client;
user: User;
}

export interface User {
// columns
id: string;
Expand All @@ -125,7 +146,9 @@ export interface User {
profile_photo_url: string;
// relations
organizations: Organization[];
notifications: Notification[];
clients: Client[];
tokens: Token[];
current_team: Organization;
owned_teams: Organization[];
teams: Organization[];
Expand Down
Loading