MCPcopy Index your code
hub / github.com/hydro-dev/Hydro / execute

Method execute

framework/framework/api.ts:147–181  ·  view source on GitHub ↗
(
        context: ApiExecutionContext, callOrName: ApiCall<ApiType, any, any> | string,
        rawArgs: any, emitHook?: any, project?: any, sendPayload?: (payload: any) => void,
    )

Source from the content-addressed store, hash-verified

145 }
146
147 async execute(
148 context: ApiExecutionContext, callOrName: ApiCall<ApiType, any, any> | string,
149 rawArgs: any, emitHook?: any, project?: any, sendPayload?: (payload: any) => void,
150 ) {
151 const call = typeof callOrName === 'string' ? APIS[callOrName] : callOrName;
152 if (!call) throw new NotFoundError(callOrName);
153 const { input, func, hooks } = call;
154 // eslint-disable-next-line no-await-in-loop
155 for (const hook of hooks) await this.execute(context, hook, rawArgs);
156
157 let args: any;
158 try {
159 args = input ? input(rawArgs as any) : rawArgs;
160 } catch (e) {
161 throw new BadRequestError(e.message);
162 }
163 if (typeof callOrName === 'string') {
164 await emitHook?.('api/before', args);
165 await emitHook?.(`api/before/${callOrName}`, args);
166 }
167 let result = await func(context, args as any, sendPayload);
168 if (result && typeof result === 'object' && 'next' in result) {
169 const it = result as AsyncGenerator<any, any, never>;
170 while (true) {
171 const value = await it.next(); // eslint-disable-line no-await-in-loop
172 if (value.done) {
173 result = value;
174 break;
175 } else {
176 sendPayload?.(value.value);
177 }
178 }
179 }
180 return (project && typeof result === 'object' && result !== null) ? projection(result, project, context) : result;
181 }
182}
183
184declare module 'cordis' {

Callers 9

removeInvalidPidFunction · 0.80
upgrade.tsFile · 0.80
calcLevelFunction · 0.80
runInDomainFunction · 0.80
udocFunction · 0.80
pdocFunction · 0.80
allMethod · 0.80
prepareMethod · 0.80
messageMethod · 0.80

Calls 2

projectionFunction · 0.85
nextMethod · 0.45

Tested by

no test coverage detected