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

Project Configuration File #143

Closed
wyatt-herkamp opened this issue Sep 17, 2023 · 2 comments
Closed

Project Configuration File #143

wyatt-herkamp opened this issue Sep 17, 2023 · 2 comments

Comments

@wyatt-herkamp
Copy link

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

@wyatt-herkamp
Copy link
Author

After seeing #30 this is kind of a duplicate.  I am not closing this. I can copy over this stuff to a comment on #30

@wyatt-herkamp
Copy link
Author

So I was looking around some more and I see that this already exist. Sorry for the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant