MCPcopy Index your code
hub / github.com/callstack/agent-device / parseUploadPreflightResult

Function parseUploadPreflightResult

src/remote/upload-client.ts:226–255  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

224}
225
226function parseUploadPreflightResult(value: unknown): UploadPreflightResult | undefined {
227 if (!value || typeof value !== 'object') {
228 return undefined;
229 }
230 const preflight = value as UploadPreflightResponse;
231 if (preflight.ok !== true || typeof preflight.uploadId !== 'string') {
232 return undefined;
233 }
234 if (preflight.cacheHit === true) {
235 return {
236 kind: 'cache-hit',
237 uploadId: preflight.uploadId,
238 };
239 }
240
241 const upload = preflight.upload;
242 if (!upload || typeof upload.url !== 'string') {
243 return undefined;
244 }
245 const headers = upload.headers ?? {};
246 if (!isStringRecord(headers)) {
247 return undefined;
248 }
249 return {
250 kind: 'direct-upload',
251 uploadId: preflight.uploadId,
252 url: upload.url,
253 headers,
254 };
255}
256
257function isStringRecord(value: unknown): value is Record<string, string> {
258 if (!value || typeof value !== 'object' || Array.isArray(value)) {

Callers 1

requestUploadPreflightFunction · 0.85

Calls 1

isStringRecordFunction · 0.85

Tested by

no test coverage detected