mirror of
https://github.com/Kludex/awesome-fastapi-projects.git
synced 2024-11-28 06:21:10 +00:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
|
"""The models for the Source Graph data."""
|
||
|
import datetime
|
||
|
from typing import Literal, NewType, Self
|
||
|
|
||
|
from pydantic import (
|
||
|
BaseModel,
|
||
|
Field,
|
||
|
HttpUrl,
|
||
|
NonNegativeInt,
|
||
|
TypeAdapter,
|
||
|
computed_field,
|
||
|
)
|
||
|
|
||
|
#: The ID of a repository from the SourceGraph API.
|
||
|
SourceGraphRepoId = NewType("SourceGraphRepoId", int)
|
||
|
|
||
|
|
||
|
class SourceGraphRepoData(BaseModel):
|
||
|
"""The data of a repository."""
|
||
|
|
||
|
type: Literal["repo"]
|
||
|
repo_id: SourceGraphRepoId = Field(..., alias="repositoryID")
|
||
|
repo_handle: str = Field(..., alias="repository")
|
||
|
stars: NonNegativeInt = Field(..., alias="repoStars")
|
||
|
last_fetched_at: datetime.datetime = Field(..., alias="repoLastFetched")
|
||
|
description: str = Field(default="")
|
||
|
|
||
|
@computed_field # type: ignore[misc]
|
||
|
@property
|
||
|
def repo_url(self: Self) -> HttpUrl:
|
||
|
"""The URL of the repository."""
|
||
|
return TypeAdapter(HttpUrl).validate_python(f"https://{self.repo_handle}")
|
||
|
|
||
|
|
||
|
#: The type adapter for the SourceGraphRepoData.
|
||
|
SourceGraphRepoDataAdapter = TypeAdapter(SourceGraphRepoData)
|
||
|
|
||
|
#: The type adapter for the SourceGraphRepoData list.
|
||
|
SourceGraphRepoDataListAdapter = TypeAdapter(list[SourceGraphRepoData])
|