Line data Source code
1 : import type {
2 : LGraph,
3 : LGraphNode,
4 : Subgraph
5 : } from '@comfyorg/graph-model/entityRegistry'
6 : import type { INodeSlot } from '@comfyorg/graph-model/interfaces'
7 : import type { ResultItemType } from '@comfyorg/api-client/resultItemTypeSchema'
8 :
9 : /**
10 : * Check if an error is an AbortError triggered by `AbortController#abort`
11 : * when cancelling a request.
12 : */
13 2356 : export const isAbortError = (
14 : err: unknown
15 : ): err is DOMException & { name: 'AbortError' } =>
16 : err instanceof DOMException && err.name === 'AbortError'
17 :
18 2356 : export const isSubgraph = (
19 : item: LGraph | Subgraph | undefined | null
20 : ): item is Subgraph => item?.isRootGraph === false
21 :
22 : /**
23 : * Check if an item is non-nullish.
24 : */
25 2356 : export const isNonNullish = <T>(item: T | undefined | null): item is T =>
26 : item != null
27 :
28 : /**
29 : * Type guard to check if a node is a subgraph input/output node.
30 : * These nodes are essential to subgraph structure and should not be removed.
31 : */
32 2356 : export const isSubgraphIoNode = (
33 : node: Omit<LGraphNode, 'constructor'> & {
34 : constructor?: LGraphNode['constructor']
35 : }
36 : ): node is LGraphNode & {
37 : constructor: { comfyClass: 'SubgraphInputNode' | 'SubgraphOutputNode' }
38 : } => {
39 0 : const nodeClass = node.constructor?.comfyClass
40 0 : return nodeClass === 'SubgraphInputNode' || nodeClass === 'SubgraphOutputNode'
41 : }
42 :
43 : /**
44 : * Type guard for slot objects (inputs/outputs)
45 : */
46 2356 : export const isSlotObject = (obj: unknown): obj is INodeSlot => {
47 37492 : return (
48 : obj !== null &&
49 : typeof obj === 'object' &&
50 : 'name' in obj &&
51 : 'type' in obj &&
52 : 'boundingRect' in obj
53 : )
54 : }
55 :
56 : /**
57 : * Type guard to check if a string is a valid ResultItemType
58 : * ResultItemType is used for asset categorization (input/output/temp)
59 : */
60 2356 : export const isResultItemType = (
61 : value: string | undefined
62 : ): value is ResultItemType => {
63 14 : return value === 'input' || value === 'output' || value === 'temp'
64 : }
|