LCOV - code coverage report
Current view: top level - src/platform/workflow/persistence/base - storageKeys.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 86.7 % 15 13
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { WORKSPACE_STORAGE_KEYS } from '@/platform/workspace/workspaceConstants'
       2              : import { isCloud } from '@/platform/distribution/types'
       3              : 
       4              : import { hashPath } from './hashUtil'
       5              : 
       6              : /**
       7              :  * Gets the current workspace ID from sessionStorage.
       8              :  * Returns 'personal' for personal workspace or when no workspace is set.
       9              :  *
      10              :  * NOTE: This is called fresh each time rather than cached at module load,
      11              :  * because the workspace auth store may not have set sessionStorage yet
      12              :  * when this module is first imported.
      13              :  */
      14       570001 : export function getWorkspaceId(): string {
      15       570001 :   if (!isCloud) return 'personal'
      16              : 
      17              :   try {
      18              :     const json = sessionStorage.getItem(
      19              :       WORKSPACE_STORAGE_KEYS.CURRENT_WORKSPACE
      20              :     )
      21              :     if (!json) return 'personal'
      22              : 
      23              :     const workspace = JSON.parse(json)
      24              :     if (workspace.type === 'personal' || !workspace.id) return 'personal'
      25              :     return workspace.id
      26              :   } catch {
      27              :     return 'personal'
      28              :   }
      29              : }
      30              : 
      31              : /**
      32              :  * Storage key generators for V2 workflow persistence.
      33              :  *
      34              :  * localStorage keys are scoped by workspaceId.
      35              :  * sessionStorage keys are scoped by clientId.
      36              :  */
      37         2356 : export const StorageKeys = {
      38              :   /**
      39              :    * Draft index key for localStorage.
      40              :    * Contains LRU order and metadata for all drafts.
      41              :    */
      42              :   draftIndex(workspaceId: string): string {
      43         8223 :     return `Comfy.Workflow.DraftIndex.v2:${workspaceId}`
      44              :   },
      45              : 
      46              :   /**
      47              :    * Individual draft payload key for localStorage.
      48              :    * @param path - Workflow path (will be hashed to create key)
      49              :    */
      50              :   draftPayload(path: string, workspaceId: string): string {
      51              :     const draftKey = hashPath(path)
      52            0 :     return `Comfy.Workflow.Draft.v2:${workspaceId}:${draftKey}`
      53              :   },
      54              : 
      55              :   /**
      56              :    * Creates a draft key (hash) from a workflow path.
      57              :    */
      58              :   draftKey(path: string): string {
      59            0 :     return hashPath(path)
      60              :   },
      61              : 
      62              :   /**
      63              :    * Active workflow pointer key for sessionStorage.
      64              :    * @param clientId - Browser tab identifier from api.clientId
      65              :    */
      66              :   activePath(clientId: string): string {
      67         1806 :     return `Comfy.Workflow.ActivePath:${clientId}`
      68              :   },
      69              : 
      70              :   /**
      71              :    * Open workflows pointer key for sessionStorage.
      72              :    * @param clientId - Browser tab identifier from api.clientId
      73              :    */
      74              :   openPaths(clientId: string): string {
      75         3658 :     return `Comfy.Workflow.OpenPaths:${clientId}`
      76              :   },
      77              : 
      78              :   agentThread(workspaceId: string): string {
      79            1 :     return `Comfy.Agent.ThreadId:${workspaceId}`
      80              :   },
      81              : 
      82              :   agentWorkflowTabBindings(workspaceId: string): string {
      83            1 :     return `Comfy.Agent.WorkflowTabBindings:${workspaceId}`
      84              :   },
      85              : 
      86              :   agentChatTitles(workspaceId: string): string {
      87            1 :     return `Comfy.Agent.ChatTitles:${workspaceId}`
      88              :   },
      89              : 
      90              :   agentDeletedThreads(workspaceId: string): string {
      91            1 :     return `Comfy.Agent.DeletedThreads:${workspaceId}`
      92              :   },
      93              : 
      94              :   agentComposerDraft(workspaceId: string): string {
      95         2355 :     return `Comfy.Agent.ComposerDraft:${workspaceId}`
      96              :   },
      97              : 
      98              :   /**
      99              :    * localStorage copies of tab pointers for cross-session restore.
     100              :    * sessionStorage is per-tab (correct for in-session use) but lost
     101              :    * on browser restart; these keys preserve the last-written state.
     102              :    */
     103              :   lastActivePath(workspaceId: string): string {
     104         4013 :     return `Comfy.Workflow.LastActivePath:${workspaceId}`
     105              :   },
     106              : 
     107              :   lastOpenPaths(workspaceId: string): string {
     108         7878 :     return `Comfy.Workflow.LastOpenPaths:${workspaceId}`
     109              :   },
     110              : 
     111              :   /**
     112              :    * Prefix patterns for cleanup operations.
     113              :    */
     114              :   prefixes: {
     115              :     draftIndex: 'Comfy.Workflow.DraftIndex.v2:',
     116              :     draftPayload: 'Comfy.Workflow.Draft.v2:',
     117              :     activePath: 'Comfy.Workflow.ActivePath:',
     118              :     openPaths: 'Comfy.Workflow.OpenPaths:',
     119              :     lastActivePath: 'Comfy.Workflow.LastActivePath:',
     120              :     lastOpenPaths: 'Comfy.Workflow.LastOpenPaths:',
     121              :     agentThread: 'Comfy.Agent.ThreadId:',
     122              :     agentWorkflowTabBindings: 'Comfy.Agent.WorkflowTabBindings:',
     123              :     agentChatTitles: 'Comfy.Agent.ChatTitles:',
     124              :     agentDeletedThreads: 'Comfy.Agent.DeletedThreads:',
     125              :     agentComposerDraft: 'Comfy.Agent.ComposerDraft:'
     126              :   }
     127              : } as const
        

Generated by: LCOV version 2.0-1