( value: unknown, )
| 17 | } |
| 18 | |
| 19 | function asWebFetchSourceMetadata( |
| 20 | value: unknown, |
| 21 | ): WebFetchSourceMetadata | null { |
| 22 | if (!isRecord(value)) { |
| 23 | return null |
| 24 | } |
| 25 | if ( |
| 26 | typeof value.source_id !== 'string' || |
| 27 | value.executor !== 'client_local_fetch' || |
| 28 | typeof value.requested_url !== 'string' || |
| 29 | typeof value.final_url !== 'string' || |
| 30 | typeof value.http_status !== 'number' || |
| 31 | typeof value.http_status_text !== 'string' || |
| 32 | typeof value.bytes_fetched !== 'number' || |
| 33 | !Array.isArray(value.redirect_chain) || |
| 34 | !value.redirect_chain.every(item => typeof item === 'string') |
| 35 | ) { |
| 36 | return null |
| 37 | } |
| 38 | |
| 39 | const metadata: WebFetchSourceMetadata = { |
| 40 | source_id: value.source_id, |
| 41 | executor: 'client_local_fetch', |
| 42 | requested_url: value.requested_url, |
| 43 | final_url: value.final_url, |
| 44 | http_status: value.http_status, |
| 45 | http_status_text: value.http_status_text, |
| 46 | bytes_fetched: value.bytes_fetched, |
| 47 | redirect_chain: value.redirect_chain, |
| 48 | } |
| 49 | if (typeof value.redirect_url === 'string') { |
| 50 | metadata.redirect_url = value.redirect_url |
| 51 | } |
| 52 | return metadata |
| 53 | } |
| 54 | |
| 55 | export function extractWebFetchSourcesFromText( |
| 56 | text: string, |
no test coverage detected