# TrashItem

> The trash: what was deleted and can still be put back.

Deleting an app, database, bucket, dict, queue, repo, volume, inbox or agent
moves it here, restorable for 30 days, then purged for good. `delete()` on each of
them returns its `TrashItem`:

```python
item = noclick.Dict.from_name("rates-cache").delete()
item.restore()   # back under its name, every key with it
```

A database's restore lands what it rewound here too, as a `database_copy`:
restoring that puts it back into its database. While it's in the trash its
name is free and its storage is billed as before; restoring is free.
`purge()` deletes it for good now: the one deletion that can't be undone, so
through MCP it waits for a person.

## noclick.TrashItem

```python
class TrashItem
```

Something deleted, restorable until `purge_after`.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `str` |  |
| `kind` | `str` |  |
| `resource_id` | `str` | Its id as it was, and will be again once restored. |
| `name` | `str | None` |  |
| `user_id` | `str | None` | The user it was deleted from (None for the account's). |
| `trashed_at` | `Any` |  |
| `purge_after` | `Any` | When it's purged for good unless restored first. |
| `operation_id` | `str | None` | The deletion's operation (on the item a `delete()` returned): `Operation.undo()` on it restores it too. |

### TrashItem.from_id

```python
noclick.TrashItem.from_id(trash_id, *, user=..., client=None) -> TrashItem
```

A lazy reference to an item in the trash by its id.

Parameters:

- `trash_id` (`str`, required)
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `TrashItem` The item; it loads the first time it's used.

Usage:

```python
item = noclick.TrashItem.from_id("4b1e2c7d-0a9f-4e6b-8c3d-5f2a1b7e9d60")
print(item.kind, item.name, item.purge_after)
```

### TrashItem.list

```python
noclick.TrashItem.list(
    *, kind=None, limit=None, user=..., client=None
) -> list[TrashItem]
```

What's in the trash, newest first: every kind, or one (`kind="dict"`).

Parameters:

- `kind` (`str | None`, default `None`)
- `limit` (`int | None`, default `None`): Return at most this many.
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `list[TrashItem]` Each item, with when it's purged unless restored first.

Usage:

```python
for item in noclick.TrashItem.list(kind="database"):
    print(item.name, item.trashed_at, item.purge_after)
```

### TrashItem.list_page

```python
noclick.TrashItem.list_page(
    *, kind=None, cursor=None, limit=None, user=..., client=None
) -> Page
```

One page of the trash; pass `next_cursor` back as `cursor`.

Parameters:

- `kind` (`str | None`, default `None`)
- `cursor` (`str | None`, default `None`): The `next_cursor` of the page before; omit it for the first page.
- `limit` (`int | None`, default `None`): Return at most this many.
- `user` (`Any`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `client` (`Client | None`, default `None`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: `Page` A page whose `data` holds the items and whose `next_cursor` is `None` on the last page.

Usage:

```python
page = noclick.TrashItem.list_page(limit=20)
print([item.name for item in page.data])
```

### TrashItem.restore

```python
trash_item.restore() -> dict[str, Any]
```

Put it back where it was, under its name, with everything in it. Refused with `noclick.Conflict`
when something new has taken its name since (rename or delete that first). A `database_copy` goes back
into its database: a restore of its own (its `operation`), which keeps what the database holds now as a
copy the same way.

Returns: `dict[str, Any]` The restored resource as its own API shows it, with `restored: True`.

Usage:

```python
item = noclick.Database.from_name("orders").delete()
restored = item.restore()
print(restored["name"], restored["status"])
```

### TrashItem.purge

```python
trash_item.purge() -> None
```

Delete it for good now rather than when `purge_after` comes: the one deletion that can't be undone.

Usage:

```python
for item in noclick.TrashItem.list(kind="bucket"):
    item.purge()
```
