-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework core and engine subgraph handling
- Loading branch information
Showing
15 changed files
with
279 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { Node, INodeState, CalculateFunction, AbstractNode } from "./node"; | ||
import { NodeInterface } from "./nodeInterface"; | ||
|
||
export interface IGraphInterface { | ||
id: string; | ||
nodeId: string; | ||
nodeInterfaceId: string; | ||
name: string; | ||
} | ||
|
||
export const GRAPH_INPUT_NODE_TYPE = "__baklava_SubgraphInputNode"; | ||
export const GRAPH_OUTPUT_NODE_TYPE = "__baklava_SubgraphOutputNode"; | ||
|
||
interface IGraphInterfaceNodeState<I, O> extends INodeState<I, O> { | ||
graphInterfaceId: string; | ||
} | ||
|
||
abstract class GraphInterfaceNode<I, O> extends Node<I, O> { | ||
public graphInterfaceId: string; | ||
|
||
constructor() { | ||
super(); | ||
this.graphInterfaceId = uuidv4(); | ||
} | ||
|
||
onPlaced() { | ||
super.onPlaced(); | ||
this.initializeIo(); | ||
} | ||
|
||
save(): IGraphInterfaceNodeState<I, O> { | ||
return { | ||
...super.save(), | ||
graphInterfaceId: this.graphInterfaceId, | ||
}; | ||
} | ||
|
||
load(state: IGraphInterfaceNodeState<I, O>) { | ||
super.load(state as INodeState<I, O>); | ||
this.graphInterfaceId = state.graphInterfaceId; | ||
} | ||
} | ||
|
||
export class GraphInputNode extends GraphInterfaceNode<{ name: string }, { placeholder: any }> { | ||
public static isGraphInputNode(v: AbstractNode): v is GraphInputNode { | ||
return v.type === GRAPH_INPUT_NODE_TYPE; | ||
} | ||
|
||
public override readonly type = GRAPH_INPUT_NODE_TYPE; | ||
public inputs = { | ||
name: new NodeInterface("Name", "Input"), | ||
}; | ||
public outputs = { | ||
placeholder: new NodeInterface("Value", undefined), | ||
}; | ||
} | ||
export type GraphInputNodeState = IGraphInterfaceNodeState<{ name: string }, { placeholder: any }>; | ||
|
||
export class GraphOutputNode extends GraphInterfaceNode<{ name: string; placeholder: any }, { output: any }> { | ||
public static isGraphOutputNode(v: AbstractNode): v is GraphOutputNode { | ||
return v.type === GRAPH_OUTPUT_NODE_TYPE; | ||
} | ||
|
||
public override readonly type = GRAPH_OUTPUT_NODE_TYPE; | ||
public inputs = { | ||
name: new NodeInterface("Name", "Output"), | ||
placeholder: new NodeInterface("Value", undefined), | ||
}; | ||
public outputs = { | ||
output: new NodeInterface("Output", undefined).setHidden(true), | ||
}; | ||
public override calculate: CalculateFunction<{ placeholder: any }, { output: any }> = ({ placeholder }) => ({ | ||
output: placeholder, | ||
}); | ||
} | ||
export type GraphOutputNodeState = IGraphInterfaceNodeState<{ name: string; placeholder: any }, { output: any }>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.