Skip to content

Commit 71dc8db

Browse files
merlinnotthechenky
authored andcommitted
Avoid abbreviations to improve readability: opts -> options (#495)
1 parent b3566bf commit 71dc8db

File tree

12 files changed

+126
-120
lines changed

12 files changed

+126
-120
lines changed

src/cloud-functions.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export interface MakeCloudFunctionArgs<EventData> {
202202
before?: (raw: Event) => void;
203203
after?: (raw: Event) => void;
204204
legacyEventType?: string;
205-
opts?: { [key: string]: any };
205+
options?: { [key: string]: any };
206206
labels?: { [key: string]: any };
207207
}
208208

@@ -222,7 +222,7 @@ export function makeCloudFunction<EventData>({
222222
return;
223223
},
224224
legacyEventType,
225-
opts = {},
225+
options = {},
226226
labels = {},
227227
}: MakeCloudFunctionArgs<EventData>): CloudFunction<EventData> {
228228
const cloudFunction: any = (data: any, context: any) => {
@@ -291,7 +291,7 @@ export function makeCloudFunction<EventData>({
291291
return {};
292292
}
293293

294-
const trigger: any = _.assign(optsToTrigger(opts), {
294+
const trigger: any = _.assign(optionsToTrigger(options), {
295295
eventTrigger: {
296296
resource: triggerResource(),
297297
eventType: legacyEventType || provider + '.' + eventType,
@@ -356,26 +356,26 @@ function _detectAuthType(event: Event) {
356356
return 'UNAUTHENTICATED';
357357
}
358358

359-
export function optsToTrigger(opts: DeploymentOptions) {
359+
export function optionsToTrigger(options: DeploymentOptions) {
360360
const trigger: any = {};
361-
if (opts.regions) {
362-
trigger.regions = opts.regions;
361+
if (options.regions) {
362+
trigger.regions = options.regions;
363363
}
364-
if (opts.timeoutSeconds) {
365-
trigger.timeout = opts.timeoutSeconds.toString() + 's';
364+
if (options.timeoutSeconds) {
365+
trigger.timeout = options.timeoutSeconds.toString() + 's';
366366
}
367-
if (opts.memory) {
367+
if (options.memory) {
368368
const memoryLookup = {
369369
'128MB': 128,
370370
'256MB': 256,
371371
'512MB': 512,
372372
'1GB': 1024,
373373
'2GB': 2048,
374374
};
375-
trigger.availableMemoryMb = _.get(memoryLookup, opts.memory);
375+
trigger.availableMemoryMb = _.get(memoryLookup, options.memory);
376376
}
377-
if (opts.schedule) {
378-
trigger.schedule = opts.schedule;
377+
if (options.schedule) {
378+
trigger.schedule = options.schedule;
379379
}
380380
return trigger;
381381
}

src/function-builder.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class FunctionBuilder {
149149
*/
150150
onRequest: (
151151
handler: (req: https.Request, resp: express.Response) => void
152-
) => https._onRequestWithOpts(handler, this.options),
152+
) => https._onRequestWithOptions(handler, this.options),
153153
/**
154154
* Declares a callable method for clients to call using a Firebase SDK.
155155
* @param handler A method that takes a data and context and returns a value.
@@ -159,7 +159,7 @@ export class FunctionBuilder {
159159
data: any,
160160
context: https.CallableContext
161161
) => any | Promise<any>
162-
) => https._onCallWithOpts(handler, this.options),
162+
) => https._onCallWithOptions(handler, this.options),
163163
};
164164
}
165165

@@ -171,7 +171,7 @@ export class FunctionBuilder {
171171
* @param instance The Realtime Database instance to use.
172172
*/
173173
instance: (instance: string) =>
174-
database._instanceWithOpts(instance, this.options),
174+
database._instanceWithOptions(instance, this.options),
175175
/**
176176
* Select Firebase Realtime Database Reference to listen to.
177177
*
@@ -195,7 +195,7 @@ export class FunctionBuilder {
195195
* about the user who triggered the Cloud Function.
196196
* @param ref Path of the database to listen to.
197197
*/
198-
ref: (path: string) => database._refWithOpts(path, this.options),
198+
ref: (path: string) => database._refWithOptions(path, this.options),
199199
};
200200
}
201201

@@ -209,13 +209,13 @@ export class FunctionBuilder {
209209
* path is "/users/Ada".
210210
*/
211211
document: (path: string) =>
212-
firestore._documentWithOpts(path, this.options),
212+
firestore._documentWithOptions(path, this.options),
213213
/** @internal */
214214
namespace: (namespace: string) =>
215-
firestore._namespaceWithOpts(namespace, this.options),
215+
firestore._namespaceWithOptions(namespace, this.options),
216216
/** @internal */
217217
database: (database: string) =>
218-
firestore._databaseWithOpts(database, this.options),
218+
firestore._databaseWithOptions(database, this.options),
219219
};
220220
}
221221

@@ -225,7 +225,7 @@ export class FunctionBuilder {
225225
* Handle events related to Crashlytics issues. An issue in Crashlytics is an
226226
* aggregation of crashes which have a shared root cause.
227227
*/
228-
issue: () => crashlytics._issueWithOpts(this.options),
228+
issue: () => crashlytics._issueWithOptions(this.options),
229229
};
230230
}
231231

@@ -236,7 +236,7 @@ export class FunctionBuilder {
236236
* @param analyticsEventType Name of the analytics event type.
237237
*/
238238
event: (analyticsEventType: string) =>
239-
analytics._eventWithOpts(analyticsEventType, this.options),
239+
analytics._eventWithOptions(analyticsEventType, this.options),
240240
};
241241
}
242242

@@ -254,9 +254,10 @@ export class FunctionBuilder {
254254
context: EventContext
255255
) => PromiseLike<any> | any
256256
) =>
257-
remoteConfig._onUpdateWithOpts(handler, this.options) as CloudFunction<
258-
remoteConfig.TemplateVersion
259-
>,
257+
remoteConfig._onUpdateWithOptions(
258+
handler,
259+
this.options
260+
) as CloudFunction<remoteConfig.TemplateVersion>,
260261
};
261262
}
262263

@@ -269,12 +270,12 @@ export class FunctionBuilder {
269270
* @param bucket Name of the Google Cloud Storage bucket to listen to.
270271
*/
271272
bucket: (bucket?: string) =>
272-
storage._bucketWithOpts(this.options, bucket),
273+
storage._bucketWithOptions(this.options, bucket),
273274

274275
/**
275276
* Handle events related to Cloud Storage objects.
276277
*/
277-
object: () => storage._objectWithOpts(this.options),
278+
object: () => storage._objectWithOptions(this.options),
278279
};
279280
}
280281

@@ -283,9 +284,9 @@ export class FunctionBuilder {
283284
/** Select Cloud Pub/Sub topic to listen to.
284285
* @param topic Name of Pub/Sub topic, must belong to the same project as the function.
285286
*/
286-
topic: (topic: string) => pubsub._topicWithOpts(topic, this.options),
287+
topic: (topic: string) => pubsub._topicWithOptions(topic, this.options),
287288
schedule: (schedule: string) =>
288-
pubsub._scheduleWithOpts(schedule, this.options),
289+
pubsub._scheduleWithOptions(schedule, this.options),
289290
};
290291
}
291292

@@ -294,7 +295,7 @@ export class FunctionBuilder {
294295
/**
295296
* Handle events related to Firebase authentication users.
296297
*/
297-
user: () => auth._userWithOpts(this.options),
298+
user: () => auth._userWithOptions(this.options),
298299
};
299300
}
300301
}

src/handler-builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class HandlerBuilder {
4747
onRequest: (
4848
handler: (req: express.Request, resp: express.Response) => void
4949
): HttpsFunction => {
50-
const func = https._onRequestWithOpts(handler, {});
50+
const func = https._onRequestWithOptions(handler, {});
5151
func.__trigger = {};
5252
return func;
5353
},
@@ -61,7 +61,7 @@ export class HandlerBuilder {
6161
context: https.CallableContext
6262
) => any | Promise<any>
6363
): HttpsFunction => {
64-
const func = https._onCallWithOpts(handler, {});
64+
const func = https._onCallWithOptions(handler, {});
6565
func.__trigger = {};
6666
return func;
6767
},

src/providers/analytics.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export const service = 'app-measurement.com';
4040
* @param analyticsEventType Name of the analytics event type.
4141
*/
4242
export function event(analyticsEventType: string) {
43-
return _eventWithOpts(analyticsEventType, {});
43+
return _eventWithOptions(analyticsEventType, {});
4444
}
4545

4646
/** @internal */
47-
export function _eventWithOpts(
47+
export function _eventWithOptions(
4848
analyticsEventType: string,
49-
opts: DeploymentOptions
49+
options: DeploymentOptions
5050
) {
5151
return new AnalyticsEventBuilder(() => {
5252
if (!process.env.GCLOUD_PROJECT) {
@@ -55,7 +55,7 @@ export function _eventWithOpts(
5555
return (
5656
'projects/' + process.env.GCLOUD_PROJECT + '/events/' + analyticsEventType
5757
);
58-
}, opts);
58+
}, options);
5959
}
6060

6161
/**
@@ -67,7 +67,7 @@ export class AnalyticsEventBuilder {
6767
/** @internal */
6868
constructor(
6969
private triggerResource: () => string,
70-
private opts: DeploymentOptions
70+
private options: DeploymentOptions
7171
) {}
7272

7373
/**
@@ -97,7 +97,7 @@ export class AnalyticsEventBuilder {
9797
legacyEventType: `providers/google.firebase.analytics/eventTypes/event.log`,
9898
triggerResource: this.triggerResource,
9999
dataConstructor,
100-
opts: this.opts,
100+
options: this.options,
101101
});
102102
}
103103
}

src/providers/auth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ export const service = 'firebaseauth.googleapis.com';
3939
* Handle events related to Firebase authentication users.
4040
*/
4141
export function user() {
42-
return _userWithOpts({});
42+
return _userWithOptions({});
4343
}
4444

4545
/** @internal */
46-
export function _userWithOpts(opts: DeploymentOptions) {
46+
export function _userWithOptions(options: DeploymentOptions) {
4747
return new UserBuilder(() => {
4848
if (!process.env.GCLOUD_PROJECT) {
4949
throw new Error('process.env.GCLOUD_PROJECT is not set.');
5050
}
5151
return 'projects/' + process.env.GCLOUD_PROJECT;
52-
}, opts);
52+
}, options);
5353
}
5454

5555
export class UserRecordMetadata implements firebase.auth.UserMetadata {
@@ -73,7 +73,7 @@ export class UserBuilder {
7373
/** @internal */
7474
constructor(
7575
private triggerResource: () => string,
76-
private opts?: DeploymentOptions
76+
private options?: DeploymentOptions
7777
) {}
7878

7979
/** Respond to the creation of a Firebase Auth user. */
@@ -105,7 +105,7 @@ export class UserBuilder {
105105
triggerResource: this.triggerResource,
106106
dataConstructor: UserBuilder.dataConstructor,
107107
legacyEventType: `providers/firebase.auth/eventTypes/${eventType}`,
108-
opts: this.opts,
108+
options: this.options,
109109
});
110110
}
111111
}

src/providers/crashlytics.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ export const service = 'fabric.io';
3737
* aggregation of crashes which have a shared root cause.
3838
*/
3939
export function issue() {
40-
return _issueWithOpts({});
40+
return _issueWithOptions({});
4141
}
4242

4343
/** @internal */
44-
export function _issueWithOpts(opts: DeploymentOptions) {
44+
export function _issueWithOptions(options: DeploymentOptions) {
4545
return new IssueBuilder(() => {
4646
if (!process.env.GCLOUD_PROJECT) {
4747
throw new Error('process.env.GCLOUD_PROJECT is not set.');
4848
}
4949
return 'projects/' + process.env.GCLOUD_PROJECT;
50-
}, opts);
50+
}, options);
5151
}
5252

5353
/** Builder used to create Cloud Functions for Crashlytics issue events. */
5454
export class IssueBuilder {
5555
/** @internal */
5656
constructor(
5757
private triggerResource: () => string,
58-
private opts: DeploymentOptions
58+
private options: DeploymentOptions
5959
) {}
6060

6161
/** @internal */
@@ -95,7 +95,7 @@ export class IssueBuilder {
9595
service,
9696
legacyEventType: `providers/firebase.crashlytics/eventTypes/${eventType}`,
9797
triggerResource: this.triggerResource,
98-
opts: this.opts,
98+
options: this.options,
9999
});
100100
}
101101
}

0 commit comments

Comments
 (0)