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

Function persistValue

apps/sim/lib/execution/payloads/store.ts:63–111  ·  view source on GitHub ↗
(
  id: string,
  json: string,
  context: LargeValueStoreContext
)

Source from the content-addressed store, hash-verified

61}
62
63async function persistValue(
64 id: string,
65 json: string,
66 context: LargeValueStoreContext
67): Promise<string | undefined> {
68 const { workspaceId, workflowId, executionId, userId } = context
69 if (!workspaceId || !workflowId || !executionId) {
70 if (context.requireDurable) {
71 throw new Error(
72 'Cannot persist large execution value without workspace, workflow, and execution IDs'
73 )
74 }
75 return undefined
76 }
77
78 const key = generateExecutionFileKey(
79 { workspaceId, workflowId, executionId },
80 `large-value-${id}.json`
81 )
82
83 try {
84 const { StorageService } = await import('@/lib/uploads')
85 const fileInfo = await StorageService.uploadFile({
86 file: Buffer.from(json, 'utf8'),
87 fileName: key,
88 contentType: 'application/json',
89 context: 'execution',
90 preserveKey: true,
91 customKey: key,
92 metadata: {
93 originalName: `large-value-${id}.json`,
94 uploadedAt: new Date().toISOString(),
95 purpose: 'execution-large-value',
96 workspaceId,
97 ...(userId ? { userId } : {}),
98 },
99 })
100 return fileInfo.key
101 } catch (error) {
102 if (context.requireDurable) {
103 throw new Error(`Failed to persist large execution value: ${toError(error).message}`)
104 }
105 logger.warn('Failed to persist large execution value, keeping in memory only', {
106 id,
107 error: toError(error).message,
108 })
109 return undefined
110 }
111}
112
113async function registerPersistedValueOwner(
114 key: string | undefined,

Callers 1

storeLargeValueFunction · 0.85

Calls 3

generateExecutionFileKeyFunction · 0.90
toErrorFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected