Skip to content

Commit 427ae7a

Browse files
merlinnotlaurenzlong
authored andcommitted
Change context parameter in handlers to be not optional (#232)
1 parent 950a9df commit 427ae7a

File tree

9 files changed

+28
-28
lines changed

9 files changed

+28
-28
lines changed

integration_test/functions/src/testing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as firebase from 'firebase-admin';
22
import * as _ from 'lodash';
33
import { EventContext } from 'firebase-functions';
44

5-
export type TestCase<T> = (data: T, context?: EventContext) => any
5+
export type TestCase<T> = (data: T, context: EventContext) => any
66
export type TestCaseMap<T> = { [key: string]: TestCase<T> };
77

88
export class TestSuite<T> {
@@ -19,7 +19,7 @@ export class TestSuite<T> {
1919
return this;
2020
}
2121

22-
run(testId: string, data: T, context?: EventContext): Promise<void> {
22+
run(testId: string, data: T, context: EventContext): Promise<void> {
2323
let running: Array<Promise<any>> = [];
2424
for (let testName in this.tests) {
2525
if (!this.tests.hasOwnProperty(testName)) { continue; }

src/cloud-functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export interface TriggerAnnotated {
165165

166166
/** A Runnable has a `run` method which directly invokes the user-defined function - useful for unit testing. */
167167
export interface Runnable<T> {
168-
run: (data: T, context?: EventContext) => PromiseLike<any> | any;
168+
run: (data: T, context: EventContext) => PromiseLike<any> | any;
169169
}
170170

171171
/**
@@ -189,7 +189,7 @@ export interface MakeCloudFunctionArgs<EventData> {
189189
triggerResource: () => string;
190190
service: string;
191191
dataConstructor?: (raw: Event | LegacyEvent) => EventData;
192-
handler: (data: EventData, context?: EventContext) => PromiseLike<any> | any;
192+
handler: (data: EventData, context: EventContext) => PromiseLike<any> | any;
193193
before?: (raw: Event | LegacyEvent) => void;
194194
after?: (raw: Event | LegacyEvent) => void;
195195
legacyEventType?: string;

src/providers/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class AnalyticsEventBuilder {
6666
* Cloud Function you can export.
6767
*/
6868
onLog(
69-
handler: (event: AnalyticsEvent, context?: EventContext) => PromiseLike<any> | any): CloudFunction<AnalyticsEvent> {
69+
handler: (event: AnalyticsEvent, context: EventContext) => PromiseLike<any> | any): CloudFunction<AnalyticsEvent> {
7070
const dataConstructor = (raw: Event) => {
7171
return new AnalyticsEvent(raw.data);
7272
};

src/providers/auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ export class UserBuilder {
6262
constructor(private triggerResource: () => string) { }
6363

6464
/** Respond to the creation of a Firebase Auth user. */
65-
onCreate(handler: (user: UserRecord, context?: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord> {
65+
onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord> {
6666
return this.onOperation(handler, 'user.create');
6767
}
6868

6969
/** Respond to the deletion of a Firebase Auth user. */
70-
onDelete(handler: (user: UserRecord, context?: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord> {
70+
onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord> {
7171
return this.onOperation(handler, 'user.delete');
7272
}
7373

7474
private onOperation(
75-
handler: (user: UserRecord, context?: EventContext) => PromiseLike<any> | any,
75+
handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any,
7676
eventType: string
7777
): CloudFunction<UserRecord> {
7878
return makeCloudFunction({

src/providers/crashlytics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ export class IssueBuilder {
5151
}
5252

5353
/** Handle Crashlytics New Issue events. */
54-
onNew(handler: (issue: Issue, context?: EventContext) => PromiseLike<any> | any): CloudFunction<Issue> {
54+
onNew(handler: (issue: Issue, context: EventContext) => PromiseLike<any> | any): CloudFunction<Issue> {
5555
return this.onEvent(handler, 'issue.new');
5656
}
5757

5858
/** Handle Crashlytics Regressed Issue events. */
59-
onRegressed(handler: (issue: Issue, context?: EventContext) => PromiseLike<any> | any): CloudFunction<Issue> {
59+
onRegressed(handler: (issue: Issue, context: EventContext) => PromiseLike<any> | any): CloudFunction<Issue> {
6060
return this.onEvent(handler, 'issue.regressed');
6161
}
6262

6363
/** Handle Crashlytics Velocity Alert events. */
64-
onVelocityAlert(handler: (issue: Issue, context?: EventContext) => PromiseLike<any> | any): CloudFunction<Issue> {
64+
onVelocityAlert(handler: (issue: Issue, context: EventContext) => PromiseLike<any> | any): CloudFunction<Issue> {
6565
return this.onEvent(handler, 'issue.velocityAlert');
6666
}
6767

6868
private onEvent(
69-
handler: (issue: Issue, context?: EventContext) => PromiseLike<any> | any,
69+
handler: (issue: Issue, context: EventContext) => PromiseLike<any> | any,
7070
eventType: string
7171
): CloudFunction<Issue> {
7272
return makeCloudFunction({

src/providers/database.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,23 @@ export class RefBuilder {
103103
/** Respond to any write that affects a ref. */
104104
onWrite(handler: (
105105
change: Change<DataSnapshot>,
106-
context?: EventContext) => PromiseLike<any> | any,
106+
context: EventContext) => PromiseLike<any> | any,
107107
): CloudFunction<Change<DataSnapshot>> {
108108
return this.onOperation(handler, 'ref.write', this.changeConstructor);
109109
}
110110

111111
/** Respond to update on a ref. */
112112
onUpdate(handler: (
113113
change: Change<DataSnapshot>,
114-
context?: EventContext) => PromiseLike<any> | any,
114+
context: EventContext) => PromiseLike<any> | any,
115115
): CloudFunction<Change<DataSnapshot>> {
116116
return this.onOperation(handler, 'ref.update', this.changeConstructor);
117117
}
118118

119119
/** Respond to new data on a ref. */
120120
onCreate(handler: (
121121
snapshot: DataSnapshot,
122-
context?: EventContext) => PromiseLike<any> | any,
122+
context: EventContext) => PromiseLike<any> | any,
123123
): CloudFunction<DataSnapshot> {
124124
let dataConstructor = (raw: LegacyEvent) => {
125125
let [dbInstance, path] = resourceToInstanceAndPath(raw.resource);
@@ -136,7 +136,7 @@ export class RefBuilder {
136136
/** Respond to all data being deleted from a ref. */
137137
onDelete(handler: (
138138
snapshot: DataSnapshot,
139-
context?: EventContext) => PromiseLike<any> | any,
139+
context: EventContext) => PromiseLike<any> | any,
140140
): CloudFunction<DataSnapshot> {
141141
let dataConstructor = (raw: LegacyEvent) => {
142142
let [dbInstance, path] = resourceToInstanceAndPath(raw.resource);
@@ -151,7 +151,7 @@ export class RefBuilder {
151151
}
152152

153153
private onOperation<T>(
154-
handler: (data: T, context?: EventContext) => PromiseLike<any> | any,
154+
handler: (data: T, context: EventContext) => PromiseLike<any> | any,
155155
eventType: string,
156156
dataConstructor: (raw: Event | LegacyEvent) => any): CloudFunction<T> {
157157

src/providers/firestore.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,37 +136,37 @@ export class DocumentBuilder {
136136
/** Respond to all document writes (creates, updates, or deletes). */
137137
onWrite(handler: (
138138
change: Change<DocumentSnapshot>,
139-
context?: EventContext) => PromiseLike<any> | any,
139+
context: EventContext) => PromiseLike<any> | any,
140140
): CloudFunction<Change<DocumentSnapshot>> {
141141
return this.onOperation(handler, 'document.write', changeConstructor);
142142
};
143143

144144
/** Respond only to document updates. */
145145
onUpdate(handler: (
146146
change: Change<DocumentSnapshot>,
147-
context?: EventContext) => PromiseLike<any> | any,
147+
context: EventContext) => PromiseLike<any> | any,
148148
): CloudFunction<Change<DocumentSnapshot>> {
149149
return this.onOperation(handler, 'document.update', changeConstructor);
150150
}
151151

152152
/** Respond only to document creations. */
153153
onCreate(handler: (
154154
snapshot: DocumentSnapshot,
155-
context?: EventContext) => PromiseLike<any> | any,
155+
context: EventContext) => PromiseLike<any> | any,
156156
): CloudFunction<DocumentSnapshot> {
157157
return this.onOperation(handler, 'document.create', snapshotConstructor);
158158
}
159159

160160
/** Respond only to document deletions. */
161161
onDelete(handler: (
162162
snapshot: DocumentSnapshot,
163-
context?: EventContext) => PromiseLike<any> | any,
163+
context: EventContext) => PromiseLike<any> | any,
164164
): CloudFunction<DocumentSnapshot> {
165165
return this.onOperation(handler, 'document.delete', beforeSnapshotConstructor);
166166
}
167167

168168
private onOperation<T>(
169-
handler: (data: T, context?: EventContext) => PromiseLike<any> | any,
169+
handler: (data: T, context: EventContext) => PromiseLike<any> | any,
170170
eventType: string,
171171
dataConstructor: (raw: Event | LegacyEvent) => any): CloudFunction<T> {
172172
return makeCloudFunction({

src/providers/pubsub.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class TopicBuilder {
4848
constructor(private triggerResource: () => string) { }
4949

5050
/** Handle a Pub/Sub message that was published to a Cloud Pub/Sub topic */
51-
onPublish(handler: (message: Message, context?: EventContext) => PromiseLike<any> | any): CloudFunction<Message> {
51+
onPublish(handler: (message: Message, context: EventContext) => PromiseLike<any> | any): CloudFunction<Message> {
5252
return makeCloudFunction({
5353
handler,
5454
provider,

src/providers/storage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,37 +75,37 @@ export class ObjectBuilder {
7575
/** Respond to archiving of an object, this is only for buckets that enabled object versioning. */
7676
onArchive(handler: (
7777
object: ObjectMetadata,
78-
context?: EventContext) => PromiseLike<any> | any,
78+
context: EventContext) => PromiseLike<any> | any,
7979
): CloudFunction<ObjectMetadata> {
8080
return this.onOperation(handler, 'object.archive');
8181
}
8282

8383
/** Respond to the deletion of an object (not to archiving, if object versioning is enabled). */
8484
onDelete(handler: (
8585
object: ObjectMetadata,
86-
context?: EventContext) => PromiseLike<any> | any,
86+
context: EventContext) => PromiseLike<any> | any,
8787
): CloudFunction<ObjectMetadata> {
8888
return this.onOperation(handler, 'object.delete');
8989
}
9090

9191
/** Respond to the successful creation of an object. */
9292
onFinalize(handler: (
9393
object: ObjectMetadata,
94-
context?: EventContext) => PromiseLike<any> | any,
94+
context: EventContext) => PromiseLike<any> | any,
9595
): CloudFunction<ObjectMetadata> {
9696
return this.onOperation(handler, 'object.finalize');
9797
}
9898

9999
/** Respond to metadata updates of existing objects. */
100100
onMetadataUpdate(handler: (
101101
object: ObjectMetadata,
102-
context?: EventContext) => PromiseLike<any> | any,
102+
context: EventContext) => PromiseLike<any> | any,
103103
): CloudFunction<ObjectMetadata> {
104104
return this.onOperation(handler, 'object.metadataUpdate');
105105
}
106106

107107
private onOperation(
108-
handler: (object: ObjectMetadata, context?: EventContext) => PromiseLike<any> | any,
108+
handler: (object: ObjectMetadata, context: EventContext) => PromiseLike<any> | any,
109109
eventType: string): CloudFunction<ObjectMetadata> {
110110
return makeCloudFunction({
111111
handler,

0 commit comments

Comments
 (0)