import { AbortSignal , createAbortSignal , withLabels , Operation , Resource } from '@effection/core' ; import { fetch as nativeFetch } from 'cross-fetch' ; /**
 * A resource that can be used to create an HTTP request. This is the return
 * value of [[fetch]]. It also contains helper methods for performing common
 * requests.
 */ export interface Fetch extends Resource < Response > { /**
     * An operation that executes the request and produces an
     * [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
     * representation of the response body.
     */ arrayBuffer ( ) : Operation < ArrayBuffer > ; /**
     * An operation that executes the request and produces a
     * [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
     * representation of the response body.
     */ blob ( ) : Operation < Blob > ; /**
     * An operation that executes the request and produces a
     * [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
     * representation of the response body.
     */ formData ( ) : Operation < FormData > ; /**
     * An operation that executes the request and produces the response body
     * parsed as JSON.
     */ json ( ) : Operation < unknown > ; /**
     * An operation that executes the request and produces the raw text of the
     * response body
     */ text ( ) : Operation < string > ; } param info param requestInit returns export function fetch ( info , requestInit = { } ) { function * init ( ) { let signal = yield createAbortSignal ( ) ; requestInit . signal = signal ; let response = yield nativeFetch ( info , requestInit ) ; return response ; } let name = `fetch('${ info }')` ; let labels = { expand : false , method : requestInit . method || 'GET' } ; return { name , labels , init , arrayBuffer : ( ) => withLabels ( function * ( ) { let response = yield { init } ; return yield response . arrayBuffer ( ) ; } , { name : `${ name }.arrayBuffer()` , ... labels } ) , blob : ( ) => withLabels ( function * ( ) { let response = yield { init } ; return yield response . blob ( ) ; } , { name : `${ name }.blob()` , ... labels } ) , formData : ( ) => withLabels ( function * ( ) { let response = yield { init } ; return yield response . formData ( ) ; } , { name : `${ name }.formData()` , ... labels } ) , json : ( ) => withLabels ( function * ( ) { let response = yield { init } ; return yield response . json ( ) ; } , { name : `${ name }.json()` , ... labels } ) , text : ( ) => withLabels ( function * ( ) { let response = yield { init } ; return yield response . text ( ) ; } , { name : `${ name }.text()` , ... labels } ) } ; }