MCPcopy Index your code
hub / github.com/simstudioai/sim / deduplicateWorkflowName

Function deduplicateWorkflowName

apps/sim/lib/workflows/utils.ts:61–109  ·  view source on GitHub ↗
(
  name: string,
  workspaceId: string,
  folderId: string | null | undefined,
  executor: Pick<typeof db, 'select'> = db
)

Source from the content-addressed store, hash-verified

59 * lookup observes workflows inserted earlier in the same transaction.
60 */
61export async function deduplicateWorkflowName(
62 name: string,
63 workspaceId: string,
64 folderId: string | null | undefined,
65 executor: Pick<typeof db, 'select'> = db
66): Promise<string> {
67 const folderCondition = folderId
68 ? eq(workflowTable.folderId, folderId)
69 : isNull(workflowTable.folderId)
70
71 const [existing] = await executor
72 .select({ id: workflowTable.id })
73 .from(workflowTable)
74 .where(
75 and(
76 eq(workflowTable.workspaceId, workspaceId),
77 folderCondition,
78 eq(workflowTable.name, name),
79 isNull(workflowTable.archivedAt)
80 )
81 )
82 .limit(1)
83
84 if (!existing) {
85 return name
86 }
87
88 for (let i = 2; i < 100; i++) {
89 const candidate = `${name} (${i})`
90 const [dup] = await executor
91 .select({ id: workflowTable.id })
92 .from(workflowTable)
93 .where(
94 and(
95 eq(workflowTable.workspaceId, workspaceId),
96 folderCondition,
97 eq(workflowTable.name, candidate),
98 isNull(workflowTable.archivedAt)
99 )
100 )
101 .limit(1)
102
103 if (!dup) {
104 return candidate
105 }
106 }
107
108 return `${name} (${generateId().slice(0, 6)})`
109}
110
111export type WorkflowResolutionResult =
112 | {

Callers 6

performCreateWorkflowFunction · 0.90
executeImportFunction · 0.90
route.tsFile · 0.90
importSingleWorkflowFunction · 0.90
route.tsFile · 0.90

Calls 2

generateIdFunction · 0.90
eqFunction · 0.50

Tested by

no test coverage detected