mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-22 15:54:09 +00:00
Amp-Thread-ID: https://ampcode.com/threads/T-019bb3bd-f607-735a-b1a8-fce5fe4f0125 Co-authored-by: Amp <amp@ampcode.com>
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
/**
|
|
* Represents a subgraph's graph object with inputs and outputs slots.
|
|
*/
|
|
export interface SubgraphGraph {
|
|
inputs: SubgraphSlot[]
|
|
outputs: SubgraphSlot[]
|
|
}
|
|
|
|
export interface SubgraphSlot {
|
|
label?: string
|
|
name?: string
|
|
displayName?: string
|
|
}
|
|
|
|
/**
|
|
* Type guard to check if a graph object is a subgraph.
|
|
*/
|
|
export function isSubgraph(graph: unknown): graph is SubgraphGraph {
|
|
return (
|
|
graph !== null &&
|
|
typeof graph === 'object' &&
|
|
'inputs' in graph &&
|
|
'outputs' in graph &&
|
|
Array.isArray((graph as SubgraphGraph).inputs) &&
|
|
Array.isArray((graph as SubgraphGraph).outputs)
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Assertion function that throws if the graph is not a subgraph.
|
|
*/
|
|
export function assertSubgraph(
|
|
graph: unknown,
|
|
message = 'Not in subgraph'
|
|
): asserts graph is SubgraphGraph {
|
|
if (!isSubgraph(graph)) {
|
|
throw new Error(message)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Inline assertion for use inside page.evaluate() browser context.
|
|
* Returns a string that can be used with Function constructor or eval.
|
|
*/
|
|
export const SUBGRAPH_ASSERT_INLINE = `
|
|
const assertSubgraph = (graph) => {
|
|
if (
|
|
graph === null ||
|
|
typeof graph !== 'object' ||
|
|
!('inputs' in graph) ||
|
|
!('outputs' in graph) ||
|
|
!Array.isArray(graph.inputs) ||
|
|
!Array.isArray(graph.outputs)
|
|
) {
|
|
throw new Error('Not in subgraph');
|
|
}
|
|
};
|
|
`
|