Skip to content

How do Graph Store, Board Server, and versioning fit together?

Dimitri Glazkov edited this page Dec 6, 2024 · 11 revisions

Graph Store

The graph store knows all graphs. It manages graph mutations and sends events whenever graphs are changed, etc. The graph store is the abstraction that enables lazy updates to currenPorts in InspectableGraph: because we can rely on GraphStore's "update" event, we can just re-read the currentPorts whenever an update comes through.

  • There are mutable and immutable graphs
  • The mutable graph (represented by a MutableGraph instance) is a graph whose topology changes.
  • The immutable graph is a graph snapshot -- it is frozen in time and can't be changed anymore.
  • The InspectableGraph instances backed by MutableGraph are great for editing use cases.
  • The InspectableGraph instances backed by immutable graph are great for capturing runs.

Versioning

Graph store needs to somehow store versions of graphs. For now, let's use plain Date timestamps to capture versions. We may go with something more sophisticated later.

Each graph in graph store has a unique ID, which is a UUID that is generated at the time of adding the graph to the store.

So, the graph store item is a MutableGraph with a list of timestamp-keyed snapshots that are its previous versions. The list is sorted by timestamp, most recent first.

To access a timestamped version, we'll need an API that gets a snapshot:

export type MutableGraphStore = TypedEventTargetType<GraphsStoreEventMap> & {
  // ...

  inspectSnapshot(
    id: MainGraphIdentifier,
    graphId: GraphIdentifier,
    timestamp?: number, // the timestamp
  ): InspectableGraph | undefined;
};

...

// Returns the first available snapshot
const snapshot = store.inspectSnapshot(id, graphId, 0);

...

// Returns the last available snapshot
const snapshot = store.inspectSnapshot(id, graphId);

...

// Returns the first snapshot that happened at or right after `timestamp`
const snapshot = store.inspectSnapshot(id, graphId, timestamp);

Brainstorming

This unique id is matched to graph URL, so maybe in the future we will just use the graph URL.

For graphs that don't have URLs (pasted in, for example), we'll create a Blob URL maybe?

Clone this wiki locally