|
@@ -7,11 +7,11 @@ type PrimitiveType = string | number | boolean;
|
|
|
export class UUID {
|
|
|
uuid: PrimitiveType;
|
|
|
|
|
|
- constructor(uuid) {
|
|
|
+ constructor(uuid: PrimitiveType) {
|
|
|
this.uuid = uuid;
|
|
|
}
|
|
|
|
|
|
- [inspect.custom](depth, options) {
|
|
|
+ [inspect.custom](depth: number, options: object) {
|
|
|
return "UUID{" + inspect(this.uuid, options) + "}"
|
|
|
}
|
|
|
}
|
|
@@ -93,11 +93,13 @@ class NodeMap {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+type UUIDCallbackType = () => UUID;
|
|
|
+
|
|
|
export class GraphState {
|
|
|
nodes: NodeMap;
|
|
|
- uuidCallback: () => UUID;
|
|
|
+ uuidCallback: UUIDCallbackType;
|
|
|
|
|
|
- constructor(uuidCallback) {
|
|
|
+ constructor(uuidCallback: UUIDCallbackType) {
|
|
|
this.nodes = new NodeMap();
|
|
|
this.uuidCallback = uuidCallback;
|
|
|
}
|
|
@@ -133,11 +135,11 @@ export class GraphState {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Set a node's outgoing edge to point to a node
|
|
|
+ // Create or update a node's outgoing edge to point to a node
|
|
|
// Idempotent.
|
|
|
setEdge(srcId: NodeId, label: string, targetId: NodeId) {
|
|
|
// gotta remove the existing edge first, if it exists
|
|
|
- this.unsetEdge(srcId, label);
|
|
|
+ this.deleteEdge(srcId, label);
|
|
|
|
|
|
const srcNode = this.nodes.get(srcId);
|
|
|
srcNode.outgoing.set(label, targetId);
|
|
@@ -145,9 +147,9 @@ export class GraphState {
|
|
|
targetNode.incoming.push({label, srcId});
|
|
|
}
|
|
|
|
|
|
- // Unset, i.e., delete an edge
|
|
|
+ // Delete an edge.
|
|
|
// Idempotent.
|
|
|
- unsetEdge(srcId: NodeId, label: string) {
|
|
|
+ deleteEdge(srcId: NodeId, label: string) {
|
|
|
const srcNode = this.nodes.get(srcId);
|
|
|
const existingTargetId = srcNode.outgoing.get(label);
|
|
|
if (existingTargetId !== undefined) {
|