(
info: DaemonArtifactEndpoint,
req: DaemonRequest,
response: Extract<DaemonResponse, { ok: true }>,
)
| 292 | } |
| 293 | |
| 294 | export async function materializeRemoteArtifacts( |
| 295 | info: DaemonArtifactEndpoint, |
| 296 | req: DaemonRequest, |
| 297 | response: Extract<DaemonResponse, { ok: true }>, |
| 298 | ): Promise<DaemonResponse> { |
| 299 | const artifacts = Array.isArray(response.data?.artifacts) ? response.data.artifacts : []; |
| 300 | if (artifacts.length === 0 || !info.baseUrl) return response; |
| 301 | const nextData = response.data ? { ...response.data } : {}; |
| 302 | const nextArtifacts: DaemonArtifact[] = []; |
| 303 | for (const artifact of artifacts) { |
| 304 | if (!artifact || typeof artifact !== 'object' || typeof artifact.artifactId !== 'string') { |
| 305 | nextArtifacts.push(artifact); |
| 306 | continue; |
| 307 | } |
| 308 | const localPath = resolveMaterializedArtifactPath(artifact, req); |
| 309 | await downloadRemoteArtifact({ |
| 310 | baseUrl: info.baseUrl, |
| 311 | token: info.token, |
| 312 | artifactId: artifact.artifactId, |
| 313 | destinationPath: localPath, |
| 314 | requestId: req.meta?.requestId, |
| 315 | }); |
| 316 | nextData[artifact.field] = localPath; |
| 317 | nextArtifacts.push({ |
| 318 | ...artifact, |
| 319 | localPath, |
| 320 | }); |
| 321 | } |
| 322 | nextData.artifacts = nextArtifacts; |
| 323 | return { ok: true, data: nextData }; |
| 324 | } |
| 325 | |
| 326 | function resolveMaterializedArtifactPath(artifact: DaemonArtifact, req: DaemonRequest): string { |
| 327 | if (artifact.localPath && artifact.localPath.trim().length > 0) { |
no test coverage detected
searching dependent graphs…