@@ -39,6 +39,7 @@ import {
3939 normalizeWorkflowEdgeTargetHandle ,
4040} from '@sim/workflow-types/workflow'
4141import { and , eq , inArray , isNull , or , type SQL , sql } from 'drizzle-orm'
42+ import type { PgInsertValue } from 'drizzle-orm/pg-core'
4243import { drizzle } from 'drizzle-orm/postgres-js'
4344import postgres from 'postgres'
4445import { env } from '@/env'
@@ -87,13 +88,13 @@ type WorkflowScopedTable = typeof workflowBlocks | typeof workflowEdges | typeof
8788 * which aborts the transaction instead of dropping that row silently.
8889 */
8990async function upsertWorkflowRows < T extends WorkflowScopedTable > (
90- tx : any ,
91+ tx : DbOrTx ,
9192 table : T ,
9293 workflowId : string ,
93- values : Array < { id : string ; workflowId : string } & Record < string , unknown > > ,
94+ values : PgInsertValue < T > [ ] ,
9495 set : Partial < Record < keyof T [ '$inferInsert' ] , SQL > >
9596) {
96- const written : Array < { id : string } > = await tx
97+ const written = await tx
9798 . insert ( table )
9899 . values ( values )
99100 . onConflictDoUpdate ( { target : table . id , set, setWhere : eq ( table . workflowId , workflowId ) } )
@@ -107,14 +108,14 @@ async function upsertWorkflowRows<T extends WorkflowScopedTable>(
107108const SUBFLOW_UPSERT_SET = {
108109 config : sql `excluded.config` ,
109110 updatedAt : sql `now()` ,
110- }
111+ } as const
111112
112113const EDGE_UPSERT_SET = {
113114 sourceBlockId : sql `excluded.source_block_id` ,
114115 targetBlockId : sql `excluded.target_block_id` ,
115116 sourceHandle : sql `excluded.source_handle` ,
116117 targetHandle : sql `excluded.target_handle` ,
117- }
118+ } as const
118119
119120interface FilterEdgesForPersistResult < T > {
120121 safeEdges : T [ ]
@@ -988,8 +989,8 @@ async function handleBlocksOperationTx(
988989 workflowId,
989990 type : block . type as string ,
990991 name : block . name as string ,
991- positionX : ( block . position as { x : number ; y : number } ) . x ,
992- positionY : ( block . position as { x : number ; y : number } ) . y ,
992+ positionX : String ( ( block . position as { x : number ; y : number } ) . x ) ,
993+ positionY : String ( ( block . position as { x : number ; y : number } ) . y ) ,
993994 data : ( block . data as Record < string , unknown > | undefined ) || { } ,
994995 subBlocks : mergedSubBlocks ,
995996 outputs : ( block . outputs as Record < string , unknown > ) || { } ,
@@ -999,7 +1000,7 @@ async function handleBlocksOperationTx(
9991000 triggerMode : ( block . triggerMode as boolean ) ?? false ,
10001001 errorEnabled : ( block . errorEnabled as boolean ) ?? false ,
10011002 retry : ( block . retry as Record < string , unknown > | undefined ) ?? null ,
1002- height : ( block . height as number ) || 0 ,
1003+ height : String ( ( block . height as number ) || 0 ) ,
10031004 locked : ( block . locked as boolean ) ?? false ,
10041005 }
10051006 } )
0 commit comments