temporal97
Getting Started

Quick Start

Build a simple temporal graph in a few lines.

import { TemporalGraph } from "temporal97";

type Node = { label: string };
type Edge = { source: string; target: string; weight: number };

const graph = new TemporalGraph<Node, Edge>();

// Snapshot 0 — add two nodes and an edge
graph.append({
  snapshot: 0,
  mutations: [
    { kind: "node", op: "set", id: "a", value: { label: "Alice" } },
    { kind: "node", op: "set", id: "b", value: { label: "Bob" } },
    { kind: "edge", op: "set", id: "a->b", value: { source: "a", target: "b", weight: 1 } },
  ],
});

// Snapshot 1 — update the edge weight
graph.append({
  snapshot: 1,
  mutations: [
    { kind: "edge", op: "set", id: "a->b", value: { source: "a", target: "b", weight: 5 } },
  ],
});

// Read current state (snapshot 1)
console.log(graph.getEdge("a->b")); // { source: "a", target: "b", weight: 5 }

// Read past state without moving the cursor
console.log(graph.getEdgeAt("a->b", 0)); // { source: "a", target: "b", weight: 1 }

// Rewind to snapshot 0
const delta = graph.rewind(0);
console.log(delta.edges.updated); // Set { "a->b" }
console.log(graph.getEdge("a->b")); // { source: "a", target: "b", weight: 1 }

Next steps

On this page