Skip to Content
Core API

Core API

createCausalDocument(dataset) provides immutable state, subscriptions and shared undo/redo. Its edit(snapshotId) provides CRUD, position commits and atomic synchronous batches. Commands return Results. querySnapshot(snapshot, revision) provides detached reads and checked collections; parseCausalJSON and serializeCausalJSON convert dataset JSON without applying or saving it. See document commands.

This reference covers the primary integration APIs in the current source workspace. The linked TypeScript source is the authority for additional exports.

import { … } from "@cytocausal/core"

No renderer, DOM or runtime dependencies. Usable in Node.js, workers and browsers.

Data types

TypeFields and contract
CausalDatasetid: string, snapshots: Snapshot[], correspondences?: Correspondence[]
Snapshotid: string, nodes: CausalNode[], edges: CausalEdge[]
CausalNodeid, label; optional evidence, position: {x, y}, metadata
CausalEdgeid, source, target; optional polarity, evidence, metadata
Polarity"positive" | "negative"; omit when unknown
Evidenceid?, text?, contributor?, all strings
Correspondencefrom, to: snapshot ids; nodes: Record<string, string>

types.ts  · Data model

validateDataset

validateDataset(dataset: CausalDataset): string[]

Returns structural issues, or []. It does not mutate the input. Checks duplicate snapshot/node/edge ids, missing edge endpoints and invalid correspondence references. It also warns when most ids change between adjacent snapshots without a correspondence (for an earlier snapshot of at least four nodes).

Not an unknown-JSON parser: malformed input can throw. It does not check node/edge cross-kind id collisions or require nonempty snapshots. Parse external values first; UI consumers require at least one snapshot.

Snapshots and identity

CallReturn and behaviour
getSnapshot(dataset, id)Snapshot; throws with known ids if absent
hasCorrespondence(dataset, from, to)boolean; checks explicit maps in either direction
getCounterparts(dataset, from, to)Record<string, string[]>; explicit maps only, including reverse merges
followNodes(dataset, from, to)NodeMapping; direct correspondence first, otherwise follows adjacent versions in array order

With no correspondence for a step, matching ids establish identity. An explicit map replaces that fallback for its pair, so list unchanged nodes too. followNodes also preserves an unclaimed same-id endpoint after a gap; see source for this fallback.

snapshots.ts 

diffSnapshots / changeMarks

diffSnapshots(dataset: CausalDataset, fromId: string, toId: string): SnapshotDiff changeMarks(diff: SnapshotDiff, side: "from" | "to"): ChangeMarks

SnapshotDiff contains addedNodes, removedNodes, renamedNodes, mergedNodes, splitNodes, regroupedNodes, addedLinks, removedLinks, changedLinks. Links are compared by corresponding endpoint groups and polarity, not just edge ids. This is not a general metadata or evidence diff.

changeMarks returns id arrays added, removed, changed, flipped for one side of the comparison.

findFeedbackLoops / findCausalPaths

findFeedbackLoops(snapshot: Snapshot, options?: LoopOptions): LoopSearch findCausalPaths(snapshot: Snapshot, from: string, to: string, options?: PathOptions): PathSearch
OptionLoopsPaths
maxLengthInfinity8
limit100050
throughOptional node id—

Length counts nodes, not edges. Both return shortest results first, with complete: false when bounds may hide results. Loops return { loops, complete }; each loop contains nodes, edges, and type: "reinforcing" | "balancing" | "unknown". An odd number of negative links balances; an even number reinforces; any missing polarity makes the type unknown.

Paths return { paths, complete } with node and edge ids in causal order. from === to returns no paths; use loop search for cycles. Searches are synchronous and can grow rapidly on dense graphs. Bound them or move them to a worker. The React UI has its own search settings; these core defaults do not describe UI defaults.

Run the analysis example

analyzeSnapshot

analyzeSnapshot(snapshot: Snapshot): SnapshotAnalysis

Returns betweenness: Record<string, number> (directed betweenness scaled so the maximum is 1; all zeros remain zero) and feedbackGroups: string[][] (strongly connected groups of more than one node, largest first). A singleton self-loop is not included in feedbackGroups; use findFeedbackLoops to enumerate it. These are structural measures, not causal effect estimates.

Evidence, search and history

CallResult
contributorsOf(item)Unique contributor names from evidence
supportOf(item)Number of unique contributors, not evidence records
listContributors(snapshot){ contributor, nodes, links }[]
filterByContributors(snapshot, names)Snapshot retaining attributed links, their endpoints and attributed nodes
combineDatasets(datasets, options){ dataset, issues }; options.id required; optional key(node, dataset), contributorOf(dataset)
searchNodes(nodes, text){ node, evidence? }[]; exact id or label/evidence substring; substring needs ≥2 characters
nodeHistory(dataset, version, nodeId)NodeHistoryEntry[]
linkHistory(dataset, version, linkId)LinkHistoryEntry[]

Combining defaults to node id as the shared concept key, and dataset id as contributor for unattributed evidence. Same-id snapshots merge. Opposite polarities stay as separate links. Inspect issues; it reports unresolved conflicts. Contributor filtering with [] yields an empty graph; the UI uses null to mean everyone, but this core function takes an array.

provenance.ts  · history.ts  · Data tutorial

Last updated on