2024-04-04 19:17:27 +02:00
|
|
|
import type { NodeInput } from "./inputs";
|
|
|
|
export type { NodeInput } from "./inputs";
|
2024-02-28 21:21:42 +01:00
|
|
|
|
2024-04-04 19:17:27 +02:00
|
|
|
export type Node = {
|
|
|
|
id: number;
|
|
|
|
type: string;
|
|
|
|
props?: Record<string, any>,
|
|
|
|
tmp?: {
|
|
|
|
depth?: number;
|
|
|
|
mesh?: any;
|
|
|
|
parents?: Node[],
|
|
|
|
children?: Node[],
|
|
|
|
inputNodes?: Record<string, Node>
|
|
|
|
type?: NodeType;
|
|
|
|
downX?: number;
|
|
|
|
downY?: number;
|
|
|
|
x?: number;
|
|
|
|
y?: number;
|
|
|
|
ref?: HTMLElement;
|
|
|
|
visible?: boolean;
|
|
|
|
isMoving?: boolean;
|
|
|
|
},
|
|
|
|
meta?: {
|
|
|
|
title?: string;
|
|
|
|
lastModified?: string;
|
|
|
|
},
|
|
|
|
position: [x: number, y: number]
|
|
|
|
}
|
|
|
|
|
|
|
|
export type NodeType = {
|
|
|
|
id: string;
|
|
|
|
inputs?: Record<string, NodeInput>
|
|
|
|
outputs?: string[];
|
|
|
|
meta?: {
|
|
|
|
title?: string;
|
|
|
|
},
|
2024-04-05 18:03:23 +02:00
|
|
|
execute?: (...args: (string | number | boolean)[]) => unknown;
|
2024-04-04 19:17:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export type Socket = {
|
|
|
|
node: Node;
|
|
|
|
index: number | string;
|
|
|
|
position: [number, number];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export interface NodeRegistry {
|
2024-04-10 21:57:03 +02:00
|
|
|
/**
|
|
|
|
* The status of the node registry
|
|
|
|
* @remarks The status should be "loading" when the registry is loading, "ready" when the registry is ready, and "error" if an error occurred while loading the registry
|
|
|
|
*/
|
|
|
|
status: "loading" | "ready" | "error";
|
2024-04-05 16:45:57 +02:00
|
|
|
/**
|
|
|
|
* Load the nodes with the given ids
|
|
|
|
* @param nodeIds - The ids of the nodes to load
|
|
|
|
* @returns A promise that resolves when the nodes are loaded
|
|
|
|
* @throws An error if the nodes could not be loaded
|
|
|
|
* @remarks This method should be called before calling getNode or getAllNodes
|
|
|
|
*/
|
|
|
|
load: (nodeIds: string[]) => Promise<void>;
|
|
|
|
/**
|
|
|
|
* Get a node by id
|
|
|
|
* @param id - The id of the node to get
|
|
|
|
* @returns The node with the given id, or undefined if no such node exists
|
|
|
|
*/
|
2024-04-04 19:17:27 +02:00
|
|
|
getNode: (id: string) => NodeType | undefined;
|
2024-04-05 16:45:57 +02:00
|
|
|
/**
|
|
|
|
* Get all nodes
|
|
|
|
* @returns An array of all nodes
|
|
|
|
*/
|
2024-04-04 19:17:27 +02:00
|
|
|
getAllNodes: () => NodeType[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RuntimeExecutor {
|
2024-04-10 21:57:03 +02:00
|
|
|
/**
|
|
|
|
* Execute the given graph
|
|
|
|
* @param graph - The graph to execute
|
|
|
|
* @returns The result of the execution
|
|
|
|
*/
|
2024-04-04 19:17:27 +02:00
|
|
|
execute: (graph: Graph) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export type Edge = [Node, number, Node, string];
|
|
|
|
|
|
|
|
export type Graph = {
|
|
|
|
id: number;
|
|
|
|
meta?: {
|
|
|
|
title?: string;
|
|
|
|
lastModified?: string;
|
|
|
|
},
|
|
|
|
nodes: Node[];
|
|
|
|
edges: [number, number, number, string][];
|
2024-02-28 21:21:42 +01:00
|
|
|
}
|