@@ -24,6 +24,7 @@ import { apps } from './apps';
2424import * as _ from 'lodash' ;
2525import { Request , Response } from 'express' ;
2626export { Request , Response } ;
27+ const WILDCARD_REGEX = new RegExp ( '{[^/{}]*}' , 'g' ) ;
2728
2829/** An event to be handled in a developer's Cloud Function */
2930export interface Event < T > {
@@ -72,6 +73,22 @@ export interface MakeCloudFunctionArgs<EventData> {
7273 after ?: ( raw : Event < any > ) => void ;
7374}
7475
76+ function _makeParams ( event : Event < any > , triggerResource : string ) : { [ option : string ] : any } {
77+ let wildcards = triggerResource . match ( WILDCARD_REGEX ) ;
78+ let params = { } ;
79+ if ( wildcards ) {
80+ let triggerResourceParts = _ . split ( triggerResource , '/' ) ;
81+ let eventResourceParts = _ . split ( event . resource , '/' ) ;
82+ _ . forEach ( wildcards , wildcard => {
83+ let wildcardNoBraces = wildcard . slice ( 1 , - 1 ) ;
84+
85+ let position = _ . indexOf ( triggerResourceParts , wildcard ) ;
86+ params [ wildcardNoBraces ] = eventResourceParts [ position ] ;
87+ } ) ;
88+ }
89+ return params ;
90+ } ;
91+
7592/** @internal */
7693export function makeCloudFunction < EventData > ( {
7794 provider,
@@ -88,7 +105,7 @@ export function makeCloudFunction<EventData>({
88105 . then ( ( ) => {
89106 let typedEvent : Event < EventData > = _ . cloneDeep ( event ) ;
90107 typedEvent . data = dataConstructor ( event ) ;
91- typedEvent . params = event . params || { } ;
108+ typedEvent . params = _makeParams ( event , resource ) || { } ;
92109 return handler ( typedEvent ) ;
93110 } ) . then ( result => {
94111 if ( after ) { after ( event ) ; }
0 commit comments