MCPcopy
hub / github.com/baidu/amis / wrappedFetcher

Function wrappedFetcher

packages/amis-core/src/utils/api.ts:546–686  ·  view source on GitHub ↗
(
    api: Api,
    data: object,
    options?: object
  )

Source from the content-addressed store, hash-verified

544 }
545
546 const wrappedFetcher = async function (
547 api: Api,
548 data: object,
549 options?: object
550 ) {
551 api = buildApi(api, data, options) as ApiObject;
552 (api as ApiObject).context = data;
553
554 const adaptors = requestAdaptors.concat();
555 if (api.requestAdaptor) {
556 const adaptor = api.requestAdaptor;
557 adaptors.unshift(async (api: ApiObject, context) => {
558 const originQuery = api.query;
559 const originQueryCopy = isPlainObject(api.query)
560 ? cloneDeep(api.query)
561 : api.query;
562
563 debug('api', 'before requestAdaptor', api);
564 api = (await adaptor.call(api, api, context)) || api;
565
566 if (
567 typeof api.url === 'string' &&
568 (api.query !== originQuery ||
569 (isPlainObject(api.query) && !isEqual(api.query, originQueryCopy)))
570 ) {
571 // 如果 api.data 有变化,且是 get 请求,那么需要重新构建 url
572 const idx = api.url.indexOf('?');
573 api.url = `${
574 ~idx ? api.url.substring(0, idx) : api.url
575 }?${qsstringify(api.query)}`;
576 }
577 debug('api', 'after requestAdaptor', api);
578 return api;
579 });
580 }
581
582 // 执行所有的发送适配器
583 if (adaptors.length) {
584 api = await adaptors.reduce(async (api, fn) => {
585 let ret: any = await api;
586 ret = (await fn(ret, data)) || ret;
587 return ret as ApiObject;
588 }, Promise.resolve(api));
589 }
590
591 if (
592 api.data &&
593 (api.data instanceof FormData ||
594 hasFile(api.data) ||
595 api.dataType === 'form-data')
596 ) {
597 api.data =
598 api.data instanceof FormData
599 ? api.data
600 : object2formData(api.data, api.qsOptions);
601 } else if (
602 api.data &&
603 typeof api.data !== 'string' &&

Callers

nothing calls this directly

Calls 15

debugFunction · 0.90
qsstringifyFunction · 0.90
hasFileFunction · 0.90
object2formDataFunction · 0.90
buildApiFunction · 0.85
wrapAdaptorFunction · 0.85
lazyResolveFunction · 0.85
isValidApiFunction · 0.85
trackerFunction · 0.85
jsonpFetcherFunction · 0.85
jsFetcherFunction · 0.85
getApiCacheFunction · 0.85

Tested by

no test coverage detected