# 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.

## TrashItem

```typescript
class TrashItem
```

Something deleted, restorable until `purgeAfter`.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `kind` | `TrashKind` | What it is. |
| `resourceId` | `string` | Its id as it was, and will be again once restored. |
| `name` | `string | null` |  |
| `userId` | `string | null` | The user it was deleted from (null for the account's). |
| `trashedAt` | `Date | null` |  |
| `purgeAfter` | `Date | null` | When it's purged for good unless restored first. |
| `operationId` | `string | null` | The deletion's operation (on the item a `delete()` returned): `Operation.undo()` on it restores it too. |

Types:

```typescript
type TrashKind =
  | "project" | "database" | "database_copy" | "bucket" | "dict" | "queue" | "repo" | "volume" | "inbox" | "agent"
  | "skill" | "memory";
```

### TrashItem.fromId

```typescript
static fromId(trashId: string, options?: CallOptions): TrashItem
```

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

Parameters:

- `trashId` (`string`, required)
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

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

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

### TrashItem.list

```typescript
static list(
  options?: TrashListOptions & { limit?: number },
): Promise<TrashItem[]>
```

What's in the trash, newest first.

Parameters:

- `options.kind` (`TrashKind`): One kind; omitted, every kind.
- `options.limit` (`number`): Return at most this many.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).

Returns: Each item, with when it's purged unless restored first.

Types:

```typescript
type TrashKind =
  | "project" | "database" | "database_copy" | "bucket" | "dict" | "queue" | "repo" | "volume" | "inbox" | "agent"
  | "skill" | "memory";

/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;
```

### TrashItem.listPage

```typescript
static listPage(
  options?: TrashListOptions & PageOptions,
): Promise<Page<TrashItem>>
```

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

Parameters:

- `options.kind` (`TrashKind`): One kind; omitted, every kind.
- `options.cursor` (`string | null`): The `next_cursor` of the page before; omit it for the first page.
- `options.limit` (`number`): Return at most this many.
- `options.user` (`UserOption`, default: the current user): `undefined` = the ambient user (`asUser`), `null` = the account itself.
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.userFilter` (`UserFilter`): Which users the read covers (`user_id` query), instead of acting as one (`user`).

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

Types:

```typescript
type TrashKind =
  | "project" | "database" | "database_copy" | "bucket" | "dict" | "queue" | "repo" | "volume" | "inbox" | "agent"
  | "skill" | "memory";

/**
 * Which users a read covers: `ALL_USERS`, `NO_USER`, a `User` or your id for one. Sent as the
 * `user_id` query parameter, never as the `NoClick-User` header, so it filters without acting as the user.
 */
type UserFilter = typeof ALL_USERS | typeof NO_USER | UserRef;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;
```

### TrashItem.restore

```typescript
restore(): Promise<JsonObject>
```

Put it back where it was, under its name, with everything in it; throws `Conflict` when
something new has taken its name since. 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 the restored resource as its own API shows it.

Returns: The restored resource as its own API shows it, with `restored: True`.

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### TrashItem.purge

```typescript
purge(): Promise<void>
```

Delete it for good now: the one deletion that can't be undone.

## DeletePreview

```typescript
interface DeletePreview
```

What a deletion would do, in words a person reads before agreeing: what it `deletes`, what stops working
(`dependsOnIt`), the data that goes (`dataLost`), what stops being billed (`stopsBilling`), and whether it's
`reversible` and how (`undo`). Nothing is deleted by asking. `confirmToken` is what a call through MCP sends to
confirm it, within `expiresInS`.

| Attribute | Type | Description |
| --- | --- | --- |
| `deletes` | `string` |  |
| `dependsOnIt` | `string[]` |  |
| `dataLost` | `string[]` |  |
| `stopsBilling` | `string[]` |  |
| `reversible` | `boolean` |  |
| `undo` | `string | null` |  |
| `confirmToken` | `string | null` |  |
| `expiresInS` | `number | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## previewDelete

```typescript
function previewDelete(
  method: "DELETE" | "POST",
  path: string,
  options?: { body?: unknown; user?: UserOption; client?: NoClick },
): Promise<DeletionPreview>
```

What `method path` would delete (`DELETE`, or `POST` for a cancel, close or clear), as the account sees it (`user`:
as one of its users does): what goes, what depends on it, what data is lost and whether it can be taken back.
`body` is the call's own, for a deletion judged by it (a workflow's edits that remove steps). Nothing is deleted.

    const { impact } = await previewDelete("DELETE", `/v1/agents/${agent.id}`);
    console.log(impact.deletes, impact.reversible ? impact.undo : "for good");

Parameters:

- `method` (`"DELETE" | "POST"`, required)
- `path` (`string`, required)
- `options.body` (`unknown`)
- `options.user` (`UserOption`, default: the current user): Who the call acts for. Defaults to the user set by `noclick.as_user` (none: the account itself).
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The preview.

Types:

```typescript
/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

## DeletionPreview

```typescript
interface DeletionPreview
```

A deletion previewed: its `operation`, `method` and `path`, what it's called (`title`), its `impact`, and the
`confirmToken` (good for `expiresInS` seconds) the call takes.

| Attribute | Type | Description |
| --- | --- | --- |
| `operation` | `string` |  |
| `method` | `string` |  |
| `path` | `string` |  |
| `title` | `string | null` |  |
| `impact` | `DeletionImpact` |  |
| `confirmToken` | `string` |  |
| `expiresInS` | `number` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## DeletionImpact

```typescript
interface DeletionImpact
```

What a deletion does, in words a person reads before agreeing; `effects` says some of `dependsOnIt` as data too.

| Attribute | Type | Description |
| --- | --- | --- |
| `deletes` | `string` |  |
| `dependsOnIt` | `string[]` | What has to go first, or stops working with it. |
| `dataLost` | `string[]` |  |
| `stopsBilling` | `string[]` |  |
| `reversible` | `boolean` | Whether it can be taken back (`undo` says how). |
| `undo` | `string | null` |  |
| `effects` | `DeletionEffect[]` |  |

## DeletionEffect

```typescript
interface DeletionEffect
```

One line of a deletion's `dependsOnIt` said as data, for a page that groups what happens: what it's about (`kind`,
`id` and `name`, null where you can't see it), what happens to it (`outcome`, the area's own word: a listener
`moves`, `stops` or `waits`), where it goes (`to`) and the `line` that says it, word for word. Several may share a
line.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `string` |  |
| `id` | `string | null` |  |
| `name` | `string | null` |  |
| `outcome` | `string` |  |
| `to` | `{ kind: string; id: string; name: string } | null` |  |
| `line` | `string` |  |
