> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://docs.ampdb.io/api/mcp` to find what you need.

# Domain Types

The types the SDK's modules share: block ranges, dataset names and references, manifests, jobs, and tokens. Import them
from `@edgeandnode/amp`'s `Domain` namespace, or from `@edgeandnode/amp/core`.

Each export is both a schema and a TypeScript type, of the same name: `Domain.BlockRange` is the type of a block range,
and the schema that checks one. A schema can:

* Check and convert a value: `Schema.decodeUnknownSync(Domain.DatasetManifest)(json)` reads a manifest file's JSON,
  and throws when it isn't valid. `Schema.encodeSync` does the reverse.
* Create a branded value, for the types that are branded: `Domain.DatasetName.make("eth_mainnet")` throws when the
  value isn't valid (see [Effect Basics](/sdks/typescript/effect#schemas-and-branded-types)).

Many have different property names in JSON, where Amp uses snake_case: `BlockRange`'s `prevHash` is `prev_hash`.
Decoding and encoding convert them.

## Blocks and batches

### `BlockRange`

A range of blocks on one chain, which a batch of rows comes from.

| Property   | Type                                       | Description                                                                            |
| ---------- | ------------------------------------------ | -------------------------------------------------------------------------------------- |
| `network`  | `Network`                                  | The chain, like `"mainnet"`.                                                           |
| `numbers`  | `{ start: BlockNumber; end: BlockNumber }` | The first and last blocks, both included.                                              |
| `hash`     | `BlockHash`                                | The last block's hash.                                                                 |
| `prevHash` | `BlockHash`, optional                      | The hash of the block before the first, its parent. Missing for a chain's first block. |

```ts
{
  network: "mainnet",
  numbers: { start: 24000000, end: 24000099 },
  hash: "0x6ed4b3511195052eea47925fe5035f5e3fc528440eed62649ba82058a1b70e40",
  prevHash: "0xe8f20171e085c248ac4d60b65ddeb9c1bd679149cc1be9925ad58799dc380b25",
}
```

### `RecordBatchMetadata`

What Amp says about a batch of results: `ranges`, its `BlockRange`s, one per chain; and `rangesComplete`, `true` once
all the rows for those ranges have arrived. `RecordBatchMetadataFromUint8Array` decodes it from the bytes Amp sends
with each batch.

### Block types

| Type          | What it is                                                              | Check                                             |
| ------------- | ----------------------------------------------------------------------- | ------------------------------------------------- |
| `BlockNumber` | A block's number                                                        | A non-negative integer. Branded.                  |
| `BlockHash`   | A block's hash                                                          | `0x` and 64 lowercase letters or digits. Branded. |
| `Network`     | A chain's name, as its datasets and providers call it, like `"mainnet"` | Lowercase. Branded.                               |

## Datasets

### `DatasetReference`

A dataset and one of its revisions: `{ namespace, name, revision }`. As a string, `namespace/name@revision`, like
`acme/eth_mainnet@1.0.0`.

* `DatasetReferenceFromString` reads one from that string:
  `Schema.decodeUnknownSync(Domain.DatasetReferenceFromString)("acme/eth_mainnet@1.0.0")`. Without a namespace, it's
  `_`, and without a revision, `dev`.
* `DatasetReferenceString` is the string, checked against that format.

### `DatasetRevision`

Which version of a dataset to use: a `DatasetVersion` (`"1.0.0"`), a `DatasetHash`, or a `DatasetTag` (`"latest"` or
`"dev"`). `latest` is the highest version, and `dev` the last manifest registered, with or without a version.

### Name and version types

| Type                    | What it is                                                                                                                             | Check                                                                           |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| `DatasetNamespace`      | Who a dataset belongs to, like `"acme"` or `"edgeandnode"`; `"_"` when none is given                                                   | Lowercase letters, digits, and underscores. Branded.                            |
| `DatasetName`           | A dataset's name, like `"eth_mainnet"`                                                                                                 | Lowercase letters, digits, and underscores, not starting with a digit. Branded. |
| `DatasetVersion`        | A version, in [semantic versioning](https://semver.org), like `"1.0.0"` or `"1.0.0-dev123"`                                            | A semantic version. Branded.                                                    |
| `DatasetHash`           | A manifest's SHA-256 hash, which identifies its exact contents                                                                         | 64 hexadecimal characters. Branded.                                             |
| `DatasetTag`            | `"latest"` or `"dev"`                                                                                                                  | Branded.                                                                        |
| `DatasetNameAndVersion` | A name and a version, like `"uniswap@1.0.0"`                                                                                           | A name, `@`, and a semantic version.                                            |
| `DatasetKind`           | What kind of dataset: `"manifest"` (derived), `"static"`, or a raw kind                                                                | Branded.                                                                        |
| `RawDatasetKind`        | The kinds of raw datasets: `"evm-rpc"`, `"solana"`, `"eth-beacon"`, `"bittensor"`, `"tempo"`, `"bitcoin-rpc"`, `"stellar"`, `"phaser"` |                                                                                 |
| `DatasetVisibility`     | `"public"` or `"private"`                                                                                                              |                                                                                 |

[Datasets](/get-started/concepts/datasets) explains namespaces, names, versions, and kinds.

### Metadata types

The metadata a dataset can have, for people to find and understand it:

| Type                 | What it is                                                                                                                      |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `DatasetMetadata`    | `namespace` and `name`, and optional `readme`, `repository`, `description`, `keywords`, `sources`, `license`, and `visibility`. |
| `DatasetDescription` | What it's for: a string of up to 1,024 characters.                                                                              |
| `DatasetReadme`      | Its documentation, a string.                                                                                                    |
| `DatasetRepository`  | The `URL` of its source code.                                                                                                   |
| `DatasetKeyword`     | A word to find it by, like `"DeFi"`.                                                                                            |
| `DatasetSource`      | Where its data comes from, like `"mainnet_rpc.logs"` or a contract address.                                                     |
| `DatasetLicense`     | Its license, like `"MIT"`.                                                                                                      |
| `DatasetInfo`        | `name`, `kind`, and `tables`, each a `TableInfo`: `name`, `network`, and `activeLocation`, where its files are.                 |
| `DatasetConfig`      | A derived dataset's configuration: its metadata, `network`, `startBlock`, `dependencies`, and its `tables` and `functions`.     |

## Manifests

### `DatasetManifest`

A dataset's [manifest](/datasets/manifests): one of three kinds, told apart by `kind`. Read a manifest file with
`Schema.decodeUnknownSync(Domain.DatasetManifest)(json)`.

| Type             | `kind`             | Properties                                                                                                                                                                                                  |
| ---------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DatasetRaw`     | A `RawDatasetKind` | `network`; `tables`, each a `RawDatasetTable`; and optional `startBlock`, `finalizedBlocksOnly`, and `stateSnapshots`. See [Raw Datasets](/datasets/raw-datasets).                                          |
| `DatasetDerived` | `"manifest"`       | Optional `dependencies`, the datasets it reads, by alias, as `DatasetReference`s; `tables`, each a `Table`; and `functions`, each a `FunctionManifest`. See [Derived Datasets](/datasets/derived-datasets). |
| `DatasetStatic`  | `"static"`         | `tables`, each a `StaticDatasetTable`. See [Static Datasets](/datasets/static-datasets).                                                                                                                    |

### Manifest parts

| Type                      | What it is                                                                                                                                                           |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `RawDatasetTable`         | A raw dataset's table: `schema`, `network`, and optional `sortedBy`, `bloomFilterColumns`, and `segmentSelectionPolicy`.                                             |
| `Table`                   | A derived dataset's table: `input`, a `TableInput` (`{ sql }`); `schema`; and optional `bloomFilterColumns`.                                                         |
| `StaticDatasetTable`      | A static dataset's table: `path`, the CSV file; `schema`; `format` (`"csv"`); `hasHeader`; and optional `sortedBy`.                                                  |
| `BloomFilterColumnConfig` | A column to build a [bloom filter](/datasets/bloom-filters) for: `column`, and optional `ndv`, how many distinct values to expect.                                   |
| `SegmentSelectionPolicy`  | How a raw table chooses its files: `"hash-linked"` or `"ordered"`.                                                                                                   |
| `StateSnapshots`          | A raw dataset's state snapshots: optional `selectors`, each a `StateSnapshotSelector`, a selector string or `{ selector, blockInterval }`.                           |
| `FunctionManifest`        | A [JavaScript function](/querying/functions/javascript): `source`, a `FunctionSource` (`{ source, filename }`), `inputTypes`, and `outputType`, as `ArrowDataType`s. |
| `FunctionDefinition`      | The same, as `getOutputSchema` takes it.                                                                                                                             |
| `TableDefinition`         | `{ sql }`, a table in a `DatasetConfig`.                                                                                                                             |

### `TableSchema`

A table's columns: `{ arrow: ArrowSchema }`, where `ArrowSchema` is `{ fields }`, and each `ArrowField` has `name`,
`type`, an `ArrowDataType`, and `nullable`. `TableSchemaInfo` is a table's `name`, `network`, and `schema`.

`ArrowDataType` is an Arrow type, as Amp writes it: a string for a type without parameters, like `"UInt64"`, or an
object for one with them, like `{ "FixedSizeBinary": 32 }` or `{ "Timestamp": ["Nanosecond", "+00:00"] }`.

## Jobs

### `JobInfo`

A [job](/managing-amp/jobs):

| Property         | Type           | Description                                                                                                                |
| ---------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `id`             | `JobId`        | Its ID, a branded number.                                                                                                  |
| `status`         | `JobStatus`    | `SCHEDULED`, `RUNNING`, `COMPLETED`, `STOPPED`, `STOP_REQUESTED`, `STOPPING`, `ERROR`, `CANCELLED`, `FATAL`, or `UNKNOWN`. |
| `descriptor`     | `any`          | What it does, like `{ kind: "materialize-raw", dataset_name: "eth_mainnet", … }`.                                          |
| `nodeId`         | `string`       | The worker, or controller, it runs on.                                                                                     |
| `idempotencyKey` | `string`       | A hash that identifies the work the job does.                                                                              |
| `createdAt`      | `DateTime.Utc` | When it was created. `DateTime.toDate` turns it into a `Date`.                                                             |
| `updatedAt`      | `DateTime.Utc` | When it last changed.                                                                                                      |

## Authentication

### `AuthInfo`

A sign-in, as the [`Auth`](/sdks/typescript/authentication#auth) service saves it:

| Property       | Type                              | Description                                                |
| -------------- | --------------------------------- | ---------------------------------------------------------- |
| `accessToken`  | `Redacted<AccessToken>`           | The token requests send.                                   |
| `refreshToken` | `Redacted<RefreshToken>`          | The token that gets a new access token.                    |
| `userId`       | `UserId`                          | Who signed in.                                             |
| `accounts`     | `ReadonlyArray<string>`, optional | Their accounts, like wallet addresses.                     |
| `expiry`       | `number`, optional                | When the access token expires, in milliseconds since 1970. |

### Token types

| Type            | What it is                                                                                                      |
| --------------- | --------------------------------------------------------------------------------------------------------------- |
| `AccessToken`   | An OAuth2 access token: a branded non-empty string.                                                             |
| `RefreshToken`  | An OAuth2 refresh token: a branded non-empty string.                                                            |
| `TokenDuration` | How long a generated token lasts: a number and a unit, like `"7 days"`, `"1 hour"`, or `"30 minutes"`. Branded. |
| `UserId`        | A user's ID, like `cmfd6bf6u006vjx0b7xb2eybx`, optionally after `did:privy:`. Branded.                          |
| `Address`       | An Ethereum address, `0x` and 40 hexadecimal characters. Branded.                                               |

## Basic types

| Type                    | What it is                                             |
| ----------------------- | ------------------------------------------------------ |
| `NonEmptyTrimmedString` | A string that isn't empty, without spaces at its ends. |
| `NonNegativeInt`        | An integer of 0 or more.                               |
