|
1 | | -/** |
2 | | - * Utility functions for converting between node IDs and their corresponding names/identifiers |
3 | | - */ |
| 1 | +import type { NodeManager, NodeType } from "@/nodeManager"; |
4 | 2 |
|
5 | | -/** |
6 | | - * Extracts the task ID from a task node ID by removing the "task_" prefix |
7 | | - */ |
8 | | -export const nodeIdToTaskId = (id: string) => id.replace(/^task_/, ""); |
| 3 | +// DEPRECATED: Legacy functions - use NodeManager instead |
| 4 | +export const taskIdToNodeId = (taskId: string): string => `task_${taskId}`; // Legacy |
| 5 | +export const inputNameToNodeId = (inputName: string): string => |
| 6 | + `input_${inputName}`; // Legacy |
| 7 | +export const outputNameToNodeId = (outputName: string): string => |
| 8 | + `output_${outputName}`; // Legacy |
9 | 9 |
|
10 | | -/** |
11 | | - * Extracts the input name from an input node ID by removing the "input_" prefix |
12 | | - */ |
13 | | -export const nodeIdToInputName = (id: string) => id.replace(/^input_/, ""); |
| 10 | +// RENAMED: For backwards compatibility and clarity |
| 11 | +export const inputNameToInputId = (inputName: string): string => inputName; // 1:1 mapping |
| 12 | +export const outputNameToOutputId = (outputName: string): string => outputName; // 1:1 mapping |
| 13 | +export const inputIdToInputName = (inputId: string): string => inputId; // 1:1 mapping |
| 14 | +export const outputIdToOutputName = (outputId: string): string => outputId; // 1:1 mapping |
14 | 15 |
|
15 | | -/** |
16 | | - * Extracts the output name from an output node ID by removing the "output_" prefix |
17 | | - */ |
18 | | -export const nodeIdToOutputName = (id: string) => id.replace(/^output_/, ""); |
| 16 | +// LEGACY: Keep for backwards compatibility |
| 17 | +export const nodeIdToTaskId = (nodeId: string): string => { |
| 18 | + return nodeId.replace(/^task_/, ""); |
| 19 | +}; |
19 | 20 |
|
20 | | -/** |
21 | | - * Creates a task node ID by adding the "task_" prefix to a task ID |
22 | | - */ |
23 | | -export const taskIdToNodeId = (taskId: string) => `task_${taskId}`; |
| 21 | +export const nodeIdToInputName = (nodeId: string): string => { |
| 22 | + return nodeId.replace(/^input_/, ""); |
| 23 | +}; |
24 | 24 |
|
25 | | -/** |
26 | | - * Creates an input node ID by adding the "input_" prefix to an input name |
27 | | - */ |
28 | | -export const inputNameToNodeId = (inputName: string) => `input_${inputName}`; |
| 25 | +export const nodeIdToOutputName = (nodeId: string): string => { |
| 26 | + return nodeId.replace(/^output_/, ""); |
| 27 | +}; |
29 | 28 |
|
30 | | -/** |
31 | | - * Creates an output node ID by adding the "output_" prefix to an output name |
32 | | - */ |
33 | | -export const outputNameToNodeId = (outputName: string) => |
34 | | - `output_${outputName}`; |
| 29 | +// NEW: NodeManager-aware functions |
| 30 | +export const getTaskIdFromNodeId = ( |
| 31 | + nodeId: string, |
| 32 | + nodeManager: NodeManager, |
| 33 | +): string | undefined => { |
| 34 | + return nodeManager.getTaskId(nodeId); |
| 35 | +}; |
| 36 | + |
| 37 | +export const getStableNodeId = ( |
| 38 | + taskId: string, |
| 39 | + nodeType: NodeType, |
| 40 | + nodeManager: NodeManager, |
| 41 | +): string => { |
| 42 | + return nodeManager.getNodeId(taskId, nodeType); |
| 43 | +}; |
0 commit comments