lepikhinb / laravel-typescript

MIT License
391 stars 46 forks source link

Make ModelGenerator account for hidden fields #17

Open dsalex1 opened 2 years ago

dsalex1 commented 2 years ago

Make ModelGenerator filter out columns that have been hidden from the serialized representation of the Model (see: https://laravel.com/docs/9.x/eloquent-serialization#hiding-attributes-from-json).

The hidden attribute is commonly used with fields like password or remember_token.

Without filtering the types generated for a model misrepresent what is commonly sent by a server for this model:

{
  "id": 1,
  "name": "Test User",
  "email": "user@user.com",
  "email_verified_at": "2022-06-29T14:51:15.000000Z",
  "created_at": "2022-06-29T09:18:09.000000Z",
  "updated_at": "2022-06-29T09:18:09.000000Z"
}

for a generated type

export interface User {
    id: number;
    name: string;
    email: string;
    email_verified_at: string | null;
    created_at: string | null;
    updated_at: string | null;
}

instead of (without filtering hidden fields)

export interface User {
    id: number;
    name: string;
    email: string;
    password: string ;
    remember_token: string ;
    email_verified_at: string | null;
    created_at: string | null;
    updated_at: string | null;
}