Skip to content

Project Configuration File #143

@wyatt-herkamp

Description

@wyatt-herkamp

So I have been using #140 and when I am repeating myself a overrides. I think it looks kind of ugly. 

For example 

#[derive(Clone, Debug, PartialEq, Eq, Serialize)]  
#[typeshare]
pub struct User {  
    #[typeshare(typescript(type = "bigint"))]  
    pub id: i64,  
    pub name: String,  
    #[typeshare(typescript(type = "string"))]  
    pub username: Username,  
    #[typeshare(typescript(type = "string"))]  
    pub email: Email,  
    #[serde(serialize_with = "common::serde_chrono::serialize_date_time_optional")]  
    #[typeshare(typescript(type = "Date"))]  
    pub email_verified: Option<DateTimeWithTimeZone>,  
    pub permissions: Permissions,  
    #[serde(serialize_with = "common::serde_chrono::serialize_date_time_optional")]  
    #[typeshare(typescript(type = "Date"))]  
    pub password_changed_at: Option<DateTimeWithTimeZone>,  
    pub password_reset_required: bool,  
    pub banned: bool,  
    #[serde(serialize_with = "common::serde_chrono::serialize_date_time")]  
    #[typeshare(typescript(type = "Date"))]  
    pub created: DateTimeWithTimeZone,  
}  

I also list a bunch of crates when I build my types file for the frontend

typeshare  --lang=typescript --output-file=frontend/src/types.ts ./server ./crates/entities/ ./crates/common

So what I was thinking was a typeshare.toml

directories = ["server", "./crates/entities/", "./crates/common"]

# Shared Overrides are used for when you are a 
# NewType struct or something that is just represented as another type 
# That typeshare knows how to handle
[overrides]
Email = "String"
[overrides.Username]
type = "String"
# Will push this to any doc comment when the type is used.
doc = '''
# Constraints
Must be between 3 and 16 characters in length. 
Must be alphanumeric. 
Username is unique to a user
'''

# Typescript Configuration
[lang.typescript]
# In the future we can provide configuration to change the formatting rules such as
ident = 2 # 2 spaces
[lang.typescript.overrides]
i64 = "bigint"
DateTimeWithTimeZone = "Date"

It will still work with something like PR #140. In the case it sees an attribute that overrides the type it will follow the attribute instead. And in the case that you add directories to the command it will just ignore what is specified in the command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions