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

Function wrapAdaptor

packages/amis-core/src/utils/api.ts:693–737  ·  view source on GitHub ↗
(
  promise: Promise<fetcherResult>,
  api: ApiObject,
  context: any
)

Source from the content-addressed store, hash-verified

691}
692
693export async function wrapAdaptor(
694 promise: Promise<fetcherResult>,
695 api: ApiObject,
696 context: any
697) {
698 const adaptors = responseAdaptors.concat();
699 if (api.adaptor) {
700 const adaptor = api.adaptor;
701 adaptors.push(
702 async (
703 payload: object,
704 response: fetcherResult,
705 api: ApiObject,
706 context: any
707 ) => {
708 debug('api', 'before adaptor data', (response as any).data);
709 let result = adaptor((response as any).data, response, api, context);
710
711 if (result?.then) {
712 result = await result;
713 }
714
715 debug('api', 'after adaptor data', result);
716 return result;
717 }
718 );
719 }
720
721 const response = await adaptors.reduce(async (promise, adaptor) => {
722 let response: any = await promise;
723 let result =
724 adaptor(response.data, response, api, context) ?? response.data;
725
726 if (result?.then) {
727 result = await result;
728 }
729
730 return {
731 ...response,
732 data: result
733 } as fetcherResult;
734 }, promise);
735
736 return responseAdaptor(response, api);
737}
738
739/**
740 * 请求远程 js 文件然后 new Function 执行,用于 schemaApi 支持 JavaScript

Callers 1

wrappedFetcherFunction · 0.85

Calls 3

debugFunction · 0.90
responseAdaptorFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected