dataset.getItemHistory()
Added in: @mastra/core@1.4.0
Retrieves the full SCD-2 (Slowly Changing Dimension Type 2) history of a specific item across all dataset versions.
Usage exampleDirect link to Usage example
import { Mastra } from "@mastra/core";
const mastra = new Mastra({ /* storage config */ });
const dataset = await mastra.datasets.get({ id: "dataset-id" });
const history = await dataset.getItemHistory({ itemId: "item-id" });
for (const row of history) {
console.log(`Version ${row.datasetVersion}: ${row.isDeleted ? "deleted" : "active"}`);
}
ParametersDirect link to Parameters
itemId:
string
ID of the item to retrieve history for.
ReturnsDirect link to Returns
result:
Promise<DatasetItemRow[]>
Array of versioned item rows, ordered by version.
DatasetItemRow
id:
string
Unique row identifier.
datasetId:
string
ID of the parent dataset.
datasetVersion:
number
Dataset version for this row.
validTo:
number | null
Version at which this row was superseded, or `null` if still current.
isDeleted:
boolean
Whether this row represents a deletion.
input:
unknown
Input data at this version.
groundTruth?:
unknown
Ground truth at this version.
metadata?:
Record<string, unknown>
Metadata at this version.
createdAt:
Date
When this row was created.
updatedAt:
Date
When this row was last updated.