Source code for bacommon.restapi.v1.workspaces

# Released under the MIT License. See LICENSE for details.
#
# See CLAUDE.md in this directory for contributor conventions.
"""Workspace response types for REST API v1."""

from __future__ import annotations

import datetime
from dataclasses import dataclass
from enum import StrEnum
from typing import Annotated

from efro.dataclassio import ioprepped, IOAttrs


[docs] class WorkspaceEntryType(StrEnum): """Type of a workspace entry.""" FILE = 'file' DIRECTORY = 'directory'
[docs] @ioprepped @dataclass class WorkspaceResponse: """Metadata for a single workspace. Returned by :attr:`~bacommon.restapi.v1.Endpoint.WORKSPACE` and :attr:`~bacommon.restapi.v1.Endpoint.WORKSPACES`. """ #: Unique workspace ID. id: str #: User-assigned workspace name. name: str #: Total size of all files in bytes. size: int #: When the workspace was created. create_time: datetime.datetime #: When the workspace was last modified. modified_time: datetime.datetime
[docs] @ioprepped @dataclass class WorkspacesResponse: """List of workspaces for the authenticated account. Returned by :attr:`~bacommon.restapi.v1.Endpoint.WORKSPACES`. """ workspaces: list[WorkspaceResponse]
[docs] @ioprepped @dataclass class WorkspaceEntryResponse: """A single file or directory entry in a workspace. Part of :class:`WorkspaceFilesResponse`. """ #: Path relative to the workspace root (e.g. ``'mymod/plugin.py'``). path: str #: Whether this entry is a file or directory. type: WorkspaceEntryType #: Size in bytes. Present for files; absent for directories. size: int | None #: Last-modified time. Present for files; may be absent for directories. modified_time: datetime.datetime | None
[docs] @ioprepped @dataclass class WorkspaceFilesResponse: """Flat listing of all files and directories in a workspace. Returned by :attr:`~bacommon.restapi.v1.Endpoint.WORKSPACE_FILES`. Entries are sorted by path. """ entries: list[WorkspaceEntryResponse]
# Docs-generation hack; import some stuff that we likely only forward-declared # in our actual source code so that docs tools can find it. from typing import (Coroutine, Any, Literal, Callable, Generator, Awaitable, Sequence, Self) import asyncio from concurrent.futures import Future from pathlib import Path from enum import Enum