cradle.sdk.types.common

 1from __future__ import annotations
 2
 3from datetime import datetime
 4from typing import Annotated, Literal, TypeAlias
 5
 6from pydantic import BaseModel, Field
 7
 8
 9class AbstractResourceResponse(BaseModel):
10    id: int = Field(description="The unique identifier of the resource")
11    created_at: datetime = Field(description="The time at which the resource was created")
12    created_by: str = Field(description="The ID of the user who created the resource")
13
14
15class ArchivableResourceMixin(BaseModel):
16    archived_at: datetime | None = Field(default=None, description="The time at which the resource was archived")
17    archived_by: str | None = Field(default=None, description="The ID of the user who archived the resource")
18
19
20class BaseListResponse(BaseModel):
21    items: list[AbstractResourceResponse] = Field(description="The listed resources.")
22    cursor: str | None = Field(
23        description="Cursor with which the next page of entries can be retrieved. If no cursor is returned, no further pages exist."
24    )
25
26
27class ContextProject(BaseModel):
28    kind: Literal["PROJECT"] = Field(default="PROJECT")
29    project_id: int
30
31
32class ContextRound(BaseModel):
33    kind: Literal["ROUND"] = Field(default="ROUND")
34    round_id: int
35
36
37class ContextWorkspace(BaseModel):
38    kind: Literal["WORKSPACE"] = Field(default="WORKSPACE")
39
40
41class ErrorResponseMixin(BaseModel):
42    """Mixin for resources that can return errors."""
43
44    errors: list[str] = Field(default_factory=list, description="List of error messages associated with the resource.")
45
46
47class ListOptions(BaseModel):
48    limit: int = Field(default=100, description="Maximum number of items to return")
49    cursor: str | None = Field(default=None, description="Continuation token returned by the previous page's response")
50    order: Literal["ASC", "DESC"] = Field(
51        default="ASC", description="Whether to order the result ascending or descending"
52    )
53
54
55class ImmutableResourceResponse(AbstractResourceResponse):
56    pass
57
58
59class ResourceResponse(AbstractResourceResponse):
60    updated_at: datetime = Field(description="The time at which the resource was last updated")
61    updated_by: str = Field(description="The ID of the user who last updated the resource")
62
63
64Context: TypeAlias = Annotated[ContextWorkspace | ContextProject | ContextRound, Field(discriminator="kind")]
class AbstractResourceResponse(pydantic.main.BaseModel):
10class AbstractResourceResponse(BaseModel):
11    id: int = Field(description="The unique identifier of the resource")
12    created_at: datetime = Field(description="The time at which the resource was created")
13    created_by: str = Field(description="The ID of the user who created the resource")
id: int = PydanticUndefined

The unique identifier of the resource

created_at: datetime.datetime = PydanticUndefined

The time at which the resource was created

created_by: str = PydanticUndefined

The ID of the user who created the resource

class ArchivableResourceMixin(pydantic.main.BaseModel):
16class ArchivableResourceMixin(BaseModel):
17    archived_at: datetime | None = Field(default=None, description="The time at which the resource was archived")
18    archived_by: str | None = Field(default=None, description="The ID of the user who archived the resource")
archived_at: datetime.datetime | None = None

The time at which the resource was archived

archived_by: str | None = None

The ID of the user who archived the resource

class BaseListResponse(pydantic.main.BaseModel):
21class BaseListResponse(BaseModel):
22    items: list[AbstractResourceResponse] = Field(description="The listed resources.")
23    cursor: str | None = Field(
24        description="Cursor with which the next page of entries can be retrieved. If no cursor is returned, no further pages exist."
25    )
items: list[AbstractResourceResponse] = PydanticUndefined

The listed resources.

cursor: str | None = PydanticUndefined

Cursor with which the next page of entries can be retrieved. If no cursor is returned, no further pages exist.

class ContextProject(pydantic.main.BaseModel):
28class ContextProject(BaseModel):
29    kind: Literal["PROJECT"] = Field(default="PROJECT")
30    project_id: int
kind: Literal['PROJECT'] = 'PROJECT'
project_id: int = PydanticUndefined
class ContextRound(pydantic.main.BaseModel):
33class ContextRound(BaseModel):
34    kind: Literal["ROUND"] = Field(default="ROUND")
35    round_id: int
kind: Literal['ROUND'] = 'ROUND'
round_id: int = PydanticUndefined
class ContextWorkspace(pydantic.main.BaseModel):
38class ContextWorkspace(BaseModel):
39    kind: Literal["WORKSPACE"] = Field(default="WORKSPACE")
kind: Literal['WORKSPACE'] = 'WORKSPACE'
class ErrorResponseMixin(pydantic.main.BaseModel):
42class ErrorResponseMixin(BaseModel):
43    """Mixin for resources that can return errors."""
44
45    errors: list[str] = Field(default_factory=list, description="List of error messages associated with the resource.")

Mixin for resources that can return errors.

errors: list[str] = PydanticUndefined

List of error messages associated with the resource.

class ListOptions(pydantic.main.BaseModel):
48class ListOptions(BaseModel):
49    limit: int = Field(default=100, description="Maximum number of items to return")
50    cursor: str | None = Field(default=None, description="Continuation token returned by the previous page's response")
51    order: Literal["ASC", "DESC"] = Field(
52        default="ASC", description="Whether to order the result ascending or descending"
53    )
limit: int = 100

Maximum number of items to return

cursor: str | None = None

Continuation token returned by the previous page's response

order: Literal['ASC', 'DESC'] = 'ASC'

Whether to order the result ascending or descending

class ImmutableResourceResponse(AbstractResourceResponse):
56class ImmutableResourceResponse(AbstractResourceResponse):
57    pass
class ResourceResponse(AbstractResourceResponse):
60class ResourceResponse(AbstractResourceResponse):
61    updated_at: datetime = Field(description="The time at which the resource was last updated")
62    updated_by: str = Field(description="The ID of the user who last updated the resource")
updated_at: datetime.datetime = PydanticUndefined

The time at which the resource was last updated

updated_by: str = PydanticUndefined

The ID of the user who last updated the resource

Context: TypeAlias = Annotated[ContextWorkspace | ContextProject | ContextRound, FieldInfo(annotation=NoneType, required=True, discriminator='kind')]