|
5 | 5 | from typing import TYPE_CHECKING, Any |
6 | 6 |
|
7 | 7 | from pydantic import BaseModel, Field |
| 8 | +from typing_extensions import Annotated, Doc |
8 | 9 |
|
9 | 10 | from .components import MetablockComponent, MetablockEntity |
| 11 | +from .utils import Filter, compact_dict, filter_as_tuple |
10 | 12 |
|
11 | 13 | if TYPE_CHECKING: |
12 | 14 | from .client import Metablock |
@@ -141,11 +143,23 @@ async def update(self, block_id: str, **kwargs: Any) -> Block: |
141 | 143 | data = await self.cli.patch(f"{self.url}/{block_id}", json=kwargs) |
142 | 144 | return block_from_data(self.cli, data) |
143 | 145 |
|
| 146 | + async def delete(self, block_id: str) -> None: |
| 147 | + """Delete a block by id""" |
| 148 | + await self.cli.delete(f"{self.url}/{block_id}") |
| 149 | + |
144 | 150 |
|
145 | 151 | class SpaceBlocks(Blocks): |
146 | | - async def get_list(self) -> list[Block]: |
| 152 | + async def get_list( |
| 153 | + self, |
| 154 | + *, |
| 155 | + name: Annotated[Filter[str] | None, Doc("Filter by block name")] = None, |
| 156 | + html: Annotated[bool | None, Doc("Filter by HTML blocks")] = None, |
| 157 | + ) -> list[Block]: |
147 | 158 | """Get a list of blocks in the space""" |
148 | | - data = await self.cli.get(self.url) |
| 159 | + data = await self.cli.get( |
| 160 | + self.url, |
| 161 | + params=compact_dict(name=filter_as_tuple(name), html=html), |
| 162 | + ) |
149 | 163 | return [block_from_data(self.cli, d) for d in data] |
150 | 164 |
|
151 | 165 | async def create(self, name: str, **kwargs: Any) -> Block: |
@@ -196,12 +210,33 @@ async def get_list(self) -> list[SpaceExtension]: |
196 | 210 | # Deployment |
197 | 211 |
|
198 | 212 |
|
199 | | -class Deployment(MetablockEntity): |
| 213 | +class Deployment(BaseModel): |
200 | 214 | """Object representing a deployment""" |
201 | 215 |
|
| 216 | + id: str = Field(description="The unique identifier of the deployment") |
| 217 | + block_id: str = Field(description="The id of the block") |
| 218 | + name: str = Field(description="The name of the deployment") |
| 219 | + env: str = Field(description="The environment of the deployment") |
| 220 | + created: datetime = Field(description="The creation date of the deployment") |
| 221 | + url: str = Field(description="The URL of the deployment") |
| 222 | + |
202 | 223 |
|
203 | 224 | class Deployments(MetablockComponent): |
204 | | - """deployments""" |
| 225 | + """Block deployments""" |
| 226 | + |
| 227 | + async def get_list( |
| 228 | + self, |
| 229 | + *, |
| 230 | + env: Annotated[str | None, Doc("Filter by deployment environment")] = None, |
| 231 | + limit: Annotated[int | None, Doc("Maximum number of spaces to return")] = None, |
| 232 | + cursor: Annotated[str | None, Doc("Cursor for pagination")] = None, |
| 233 | + ) -> list[Deployment]: |
| 234 | + """Get a list of deployments for the block""" |
| 235 | + data = await self.cli.get( |
| 236 | + self.url, |
| 237 | + params=compact_dict(env=env, limit=limit, cursor=cursor), |
| 238 | + ) |
| 239 | + return [Deployment(**d) for d in data] |
205 | 240 |
|
206 | 241 |
|
207 | 242 | # Domain |
|
0 commit comments