| 22 | * @param {any} options |
| 23 | */ |
| 24 | export function doRequest(type: DataSourceType, options: any) { |
| 25 | // eslint-disable-next-line prefer-const |
| 26 | let { uri, url, method = 'GET', headers, params, ...otherProps } = options; |
| 27 | otherProps = otherProps || {}; |
| 28 | if (type === 'jsonp') { |
| 29 | return jsonp(uri, params, otherProps); |
| 30 | } |
| 31 | |
| 32 | if (type === 'fetch') { |
| 33 | switch (method.toUpperCase()) { |
| 34 | case 'GET': |
| 35 | return get(uri, params, headers, otherProps); |
| 36 | case 'POST': |
| 37 | return post(uri, params, headers, otherProps); |
| 38 | default: |
| 39 | return request(uri, method, params, headers, otherProps); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | logger.log(`Engine default dataSource does not support type:[${type}] dataSource request!`, options); |
| 44 | } |
| 45 | |
| 46 | // TODO: according to protocol, we should implement errorHandler/shouldFetch/willFetch/requestHandler and isSync controll. |
| 47 | export class DataHelper { |