File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -80,9 +80,14 @@ export function wrap<T, V extends CloudEvent<unknown>>(
8080 | WrappedFunction < T >
8181 | WrappedV2Function < V >
8282 | WrappedV2CallableFunction < T > {
83+ if ( ! cloudFunction ) {
84+ throw new Error ( 'Cannot wrap: undefined cloud function' ) ;
85+ }
86+
8387 if ( isV2CloudFunction < V > ( cloudFunction ) ) {
84- return wrapV2 < V > ( cloudFunction as CloudFunctionV2 < V > ) ;
88+ return wrapV2 < V > ( cloudFunction ) ;
8589 }
90+
8691 return wrapV1 < T > (
8792 cloudFunction as HttpsFunctionOrCloudFunctionV1 < T , typeof cloudFunction >
8893 ) ;
@@ -93,12 +98,23 @@ export function wrap<T, V extends CloudEvent<unknown>>(
9398 * <ul>
9499 * <li> V1 CloudFunction is sometimes a binary function
95100 * <li> V2 CloudFunction is always a unary function
101+ * <li> V2 ScheduleFunction is a binary function (HttpsFunctionV2)
102+ *
96103 * <li> V1 CloudFunction.run is always a binary function
97104 * <li> V2 CloudFunction.run is always a unary function
105+ * <li> V2 ScheduleFunction.run is always a unary function
106+ * </ul>
107+ *
98108 * @return True iff the CloudFunction is a V2 function.
99109 */
100110function isV2CloudFunction < T extends CloudEvent < unknown > > (
101- cloudFunction : any
111+ cloudFunction : CloudFunctionV1 < T > | CloudFunctionV2 < T > | HttpsFunctionV2
102112) : cloudFunction is CloudFunctionV2 < T > {
103- return cloudFunction . length === 1 && cloudFunction ?. run ?. length === 1 ;
113+ if ( ! cloudFunction ) {
114+ return false ;
115+ }
116+
117+ type CloudFunctionType = CloudFunctionV1 < T > | CloudFunctionV2 < T > ;
118+
119+ return ( cloudFunction as CloudFunctionType ) . run . length === 1 ;
104120}
You can’t perform that action at this time.
0 commit comments