Line data Source code
1 : import type { LGraphNode } from '@comfyorg/graph-model/entityRegistry'
2 :
3 : /**
4 : * Extracts the custom node registry ID (cnr_id or aux_id) from a raw
5 : * properties bag.
6 : *
7 : * @param properties - The properties object to inspect
8 : * @returns The cnrId string, or undefined if not found
9 : */
10 2355 : export function getCnrIdFromProperties(
11 : properties: Record<string, unknown> | undefined | null
12 : ): string | undefined {
13 2355 : if (typeof properties?.cnr_id === 'string' && properties.cnr_id.length > 0)
14 134 : return properties.cnr_id
15 2355 : if (typeof properties?.aux_id === 'string') return properties.aux_id
16 : return undefined
17 : }
18 :
19 : /**
20 : * Extracts the custom node registry ID (cnr_id or aux_id) from a node's properties.
21 : * Returns undefined if neither property is present.
22 : *
23 : * @param node - The graph node to inspect
24 : * @returns The cnrId string, or undefined if not found
25 : */
26 2251 : export function getCnrIdFromNode(node: LGraphNode): string | undefined {
27 2251 : return getCnrIdFromProperties(node.properties)
28 : }
|