Skip to content

Commit 8e308fe

Browse files
merlinnotthechenky
authored andcommitted
Reformat comments (#496)
* Avoid abbreviations to improve readability: opts -> options * Reformat comments to be more consistent and readable
1 parent bff5bf7 commit 8e308fe

File tree

3 files changed

+170
-110
lines changed

3 files changed

+170
-110
lines changed

src/cloud-functions.ts

Lines changed: 113 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export { Request, Response };
2828

2929
const WILDCARD_REGEX = new RegExp('{[^/{}]*}', 'g');
3030

31-
/** Wire format for an event
31+
/**
32+
* Wire format for an event.
3233
* @internal
3334
*/
3435
export interface Event {
@@ -41,56 +42,78 @@ export interface Event {
4142
data: any;
4243
}
4344

44-
/** The context in which an event occurred.
45+
/**
46+
* The context in which an event occurred.
47+
*
4548
* An EventContext describes:
4649
* - The time an event occurred.
4750
* - A unique identifier of the event.
4851
* - The resource on which the event occurred, if applicable.
49-
* - Authorization of the request that triggered the event, if applicable and available.
52+
* - Authorization of the request that triggered the event, if applicable and
53+
* available.
5054
*/
5155
export interface EventContext {
52-
/** ID of the event */
56+
/**
57+
* Firebase auth variable for the user whose action triggered the function.
58+
* Field will be null for unauthenticated users, and will not exist for admin
59+
* users. Only available for database functions.
60+
*/
61+
auth?: {
62+
token: object;
63+
uid: string;
64+
};
65+
/**
66+
* Type of authentication for the triggering action. Only available for
67+
* database functions.
68+
*/
69+
authType?: 'ADMIN' | 'USER' | 'UNAUTHENTICATED';
70+
/**
71+
* ID of the event
72+
*/
5373
eventId: string;
54-
/** Timestamp for when the event occured (ISO string) */
55-
timestamp: string;
56-
/** Type of event */
74+
/**
75+
* Type of event
76+
*/
5777
eventType: string;
58-
/** Resource that triggered the event */
59-
resource: Resource;
60-
/** Key-value pairs that represent the values of wildcards in a database reference
61-
* Cannot be accessed while inside the handler namespace.
78+
/**
79+
* Key-value pairs that represent the values of wildcards in a database
80+
* reference. Cannot be accessed while inside the handler namespace.
6281
*/
6382
params: { [option: string]: any };
64-
/** Type of authentication for the triggering action, valid value are: 'ADMIN', 'USER',
65-
* 'UNAUTHENTICATED'. Only available for database functions.
83+
/**
84+
* Resource that triggered the event
6685
*/
67-
authType?: 'ADMIN' | 'USER' | 'UNAUTHENTICATED';
68-
/** Firebase auth variable for the user whose action triggered the function. Field will be
69-
* null for unauthenticated users, and will not exist for admin users. Only available
70-
* for database functions.
86+
resource: Resource;
87+
/**
88+
* Timestamp for when the event ocurred (ISO 8601 string)
7189
*/
72-
auth?: {
73-
uid: string;
74-
token: object;
75-
};
90+
timestamp: string;
7691
}
7792

78-
/** Change describes a change of state - "before" represents the state prior
79-
* to the event, "after" represents the state after the event.
93+
/**
94+
* Change describes a change of state - "before" represents the state prior to
95+
* the event, "after" represents the state after the event.
8096
*/
8197
export class Change<T> {
8298
constructor(public before: T, public after: T) {}
8399
}
84100

85-
/** ChangeJson is the JSON format used to construct a Change object. */
101+
/**
102+
* ChangeJson is the JSON format used to construct a Change object.
103+
*/
86104
export interface ChangeJson {
87-
/** Key-value pairs representing state of data before the change.
88-
* If `fieldMask` is set, then only fields that changed are present in `before`.
105+
/**
106+
* Key-value pairs representing state of data after the change.
89107
*/
90-
before?: any;
91-
/** Key-value pairs representing state of data after the change. */
92108
after?: any;
93-
/** Comma-separated string that represents names of field that changed. */
109+
/**
110+
* Key-value pairs representing state of data before the change. If
111+
* `fieldMask` is set, then only fields that changed are present in `before`.
112+
*/
113+
before?: any;
114+
/**
115+
* Comma-separated string that represents names of field that changed.
116+
*/
94117
fieldMask?: string;
95118
}
96119

@@ -99,13 +122,17 @@ export namespace Change {
99122
return x as T;
100123
}
101124

102-
/** Factory method for creating a Change from a `before` object and an `after` object. */
125+
/**
126+
* Factory method for creating a Change from a `before` object and an `after`
127+
* object.
128+
*/
103129
export function fromObjects<T>(before: T, after: T) {
104130
return new Change(before, after);
105131
}
106132

107-
/** Factory method for creating a Change from a JSON and an optional customizer function to be
108-
* applied to both the `before` and the `after` fields.
133+
/**
134+
* Factory method for creating a Change from a JSON and an optional customizer
135+
* function to be applied to both the `before` and the `after` fields.
109136
*/
110137
export function fromJSON<T>(
111138
json: ChangeJson,
@@ -121,7 +148,9 @@ export namespace Change {
121148
);
122149
}
123150

124-
/** @internal */
151+
/**
152+
* @internal
153+
*/
125154
export function applyFieldMask(
126155
sparseBefore: any,
127156
after: any,
@@ -141,8 +170,10 @@ export namespace Change {
141170
}
142171
}
143172

144-
/** Resource is a standard format for defining a resource (google.rpc.context.AttributeContext.Resource).
145-
* In Cloud Functions, it is the resource that triggered the function - such as a storage bucket.
173+
/**
174+
* Resource is a standard format for defining a resource
175+
* (google.rpc.context.AttributeContext.Resource). In Cloud Functions, it is the
176+
* resource that triggered the function - such as a storage bucket.
146177
*/
147178
export interface Resource {
148179
service: string;
@@ -151,83 +182,96 @@ export interface Resource {
151182
labels?: { [tag: string]: string };
152183
}
153184

154-
/** TriggerAnnotated is used internally by the firebase CLI to understand what type of Cloud Function to deploy. */
185+
/**
186+
* TriggerAnnotated is used internally by the firebase CLI to understand what
187+
* type of Cloud Function to deploy.
188+
*/
155189
export interface TriggerAnnotated {
156190
__trigger: {
157-
httpsTrigger?: {};
191+
availableMemoryMb?: number;
158192
eventTrigger?: {
159193
eventType: string;
160194
resource: string;
161195
service: string;
162196
};
197+
httpsTrigger?: {};
163198
labels?: { [key: string]: string };
164199
regions?: string[];
165-
timeout?: string;
166-
availableMemoryMb?: number;
167200
schedule?: Schedule;
201+
timeout?: string;
168202
};
169203
}
170204

171-
/** A Runnable has a `run` method which directly invokes the user-defined function - useful for unit testing. */
205+
/**
206+
* A Runnable has a `run` method which directly invokes the user-defined
207+
* function - useful for unit testing.
208+
*/
172209
export interface Runnable<T> {
173210
run: (data: T, context: any) => PromiseLike<any> | any;
174211
}
175212

176213
/**
177-
* An HttpsFunction is both an object that exports its trigger definitions at __trigger and
178-
* can be called as a function that takes an express.js Request and Response object.
214+
* An HttpsFunction is both an object that exports its trigger definitions at
215+
* __trigger and can be called as a function that takes an express.js Request
216+
* and Response object.
179217
*/
180218
export type HttpsFunction = TriggerAnnotated &
181219
((req: Request, resp: Response) => void);
182220

183221
/**
184-
* A CloudFunction is both an object that exports its trigger definitions at __trigger and
185-
* can be called as a function using the raw JS API for Google Cloud Functions.
222+
* A CloudFunction is both an object that exports its trigger definitions at
223+
* __trigger and can be called as a function using the raw JS API for Google
224+
* Cloud Functions.
186225
*/
187226
export type CloudFunction<T> = Runnable<T> &
188227
TriggerAnnotated &
189228
((input: any, context?: any) => PromiseLike<any> | any);
190229

191-
/** @internal */
230+
/**
231+
* @internal
232+
*/
192233
export interface MakeCloudFunctionArgs<EventData> {
193-
// TODO should remove `provider` and require a fully qualified `eventType`
194-
// once all providers have migrated to new format.
195-
provider: string;
196-
eventType: string;
197-
triggerResource: () => string;
198-
service: string;
234+
after?: (raw: Event) => void;
235+
before?: (raw: Event) => void;
236+
contextOnlyHandler?: (context: EventContext) => PromiseLike<any> | any;
199237
dataConstructor?: (raw: Event) => EventData;
238+
eventType: string;
200239
handler?: (data: EventData, context: EventContext) => PromiseLike<any> | any;
201-
contextOnlyHandler?: (context: EventContext) => PromiseLike<any> | any;
202-
before?: (raw: Event) => void;
203-
after?: (raw: Event) => void;
240+
labels?: { [key: string]: any };
204241
legacyEventType?: string;
205242
options?: { [key: string]: any };
206-
labels?: { [key: string]: any };
243+
/*
244+
* TODO: should remove `provider` and require a fully qualified `eventType`
245+
* once all providers have migrated to new format.
246+
*/
247+
provider: string;
248+
service: string;
249+
triggerResource: () => string;
207250
}
208251

209-
/** @internal */
252+
/**
253+
* @internal
254+
*/
210255
export function makeCloudFunction<EventData>({
211-
provider,
212-
eventType,
213-
triggerResource,
214-
service,
256+
after = () => {},
257+
before = () => {},
258+
contextOnlyHandler,
215259
dataConstructor = (raw: Event) => raw.data,
260+
eventType,
216261
handler,
217-
contextOnlyHandler,
218-
before = () => {
219-
return;
220-
},
221-
after = () => {
222-
return;
223-
},
262+
labels = {},
224263
legacyEventType,
225264
options = {},
226-
labels = {},
265+
provider,
266+
service,
267+
triggerResource,
227268
}: MakeCloudFunctionArgs<EventData>): CloudFunction<EventData> {
228269
const cloudFunction: any = (data: any, context: any) => {
229270
if (legacyEventType && context.eventType === legacyEventType) {
230-
// v1beta1 event flow has different format for context, transform them to new format.
271+
/*
272+
* v1beta1 event flow has different format for context, transform them to
273+
* new format.
274+
*/
231275
context.eventType = provider + '.' + eventType;
232276
context.resource = {
233277
service,

0 commit comments

Comments
 (0)