MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/functions-framework-nodejs / wrapUserFunction

Function wrapUserFunction

src/function_wrappers.ts:208–232  ·  view source on GitHub ↗
(
  userFunction: HandlerFunction<T>,
  signatureType: SignatureType,
)

Source from the content-addressed store, hash-verified

206 * @return An Express handler function that invokes the user function.
207 */
208export const wrapUserFunction = <T = unknown>(
209 userFunction: HandlerFunction<T>,
210 signatureType: SignatureType,
211): RequestHandler => {
212 switch (signatureType) {
213 case 'http':
214 return wrapHttpFunction(userFunction as HttpFunction);
215 case 'event':
216 // Callback style if user function has more than 2 arguments.
217 if (userFunction instanceof Function && userFunction!.length > 2) {
218 return wrapEventFunctionWithCallback(
219 userFunction as EventFunctionWithCallback,
220 );
221 }
222 return wrapEventFunction(userFunction as EventFunction);
223 case 'cloudevent':
224 if (userFunction instanceof Function && userFunction!.length > 1) {
225 // Callback style if user function has more than 1 argument.
226 return wrapCloudEventFunctionWithCallback(
227 userFunction as CloudEventFunctionWithCallback,
228 );
229 }
230 return wrapCloudEventFunction(userFunction as CloudEventFunction);
231 }
232};

Callers 2

getServerFunction · 0.90

Calls 5

wrapHttpFunctionFunction · 0.85
wrapEventFunctionFunction · 0.85
wrapCloudEventFunctionFunction · 0.85

Tested by

no test coverage detected