---
title: "Source collections"
description: "Create and manage an observable collection of citation sources."
canonical_url: "https://tiptap.dev/docs/citations/api-reference/sources"
---

# Source collections

Create and manage an observable collection of citation sources.

`createSources<T>(inputs)` takes an array of `SourceInput<T>` records and returns a `SourceCollection<T>`. Use `createSources<unknown>(inputs)` for mixed data shapes.

| Field         | Type                               | Description                                                                                                           |
| ------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `id`          | `string`                           | Required. A unique, nonempty ID.                                                                                      |
| `label`       | `string`                           | Required. A nonempty display label.                                                                                   |
| `data`        | `T`                                | Required. [Supported JSON data](https://tiptap.dev/docs/citations/api-reference/source-data.md), copied on insertion. |
| `revision`    | `string`                           | Optional nonempty revision managed by your application.                                                               |
| `getRevision` | `(data: SourceData<T>) => unknown` | Optional selector whose result determines the revision.                                                               |

Set `revision` or `getRevision`, or omit both to track all source data. See [revision strategies](https://tiptap.dev/docs/citations/guides/sources.md#choose-a-revision-strategy).

| Method                | Result or effect                                                                                                                                                       |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `add(input)`          | Adds a source. Duplicate IDs throw.                                                                                                                                    |
| `update(id, patch)`   | Applies a `SourceUpdate<T>`. Supplied fields replace whole values and omitted fields keep their values. Unknown IDs throw. A label-only change preserves the revision. |
| `remove(id)`          | Removes a source. Citations that reference it report `sourceMissing`. Unknown IDs throw.                                                                               |
| `get(id)`             | Returns a frozen `SourceSnapshot<T>` or `undefined`.                                                                                                                   |
| `getAll()`            | Returns a frozen snapshot array in insertion order.                                                                                                                    |
| `subscribe(listener)` | Returns an unsubscribe function. The listener receives `SourceChange` with a read-only `sourceIds` array.                                                              |
| `batch(callback)`     | Combines changes into one notification at the end of the outermost synchronous batch.                                                                                  |

A source snapshot contains `id`, `label`, `revision`, and a deeply frozen copy of `data`. Updates replace the snapshot, so earlier snapshots retain their values. To change a source's revision strategy, remove it and add it again.

Source notifications are synchronous. Label updates and data updates that keep the same revision still notify listeners. Changes inside a listener queue another notification. The collection finishes delivery before rethrowing the first listener error.

Keep batch callbacks synchronous. Nested batches notify once at the end of the outermost batch. Each changed ID appears once, in the order it first changed. If a batch throws, the collection keeps and reports successful changes.

If both the batch callback and a source listener throw, the first listener error reaches the caller.
