( userFunction: HandlerFunction<T>, signatureType: SignatureType, )
| 206 | * @return An Express handler function that invokes the user function. |
| 207 | */ |
| 208 | export 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 | }; |
no test coverage detected