Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
cache: npm
jobs:
include:
- name: lint
script: npm run lint
stage: verify
- name: format
script: npm run format
stage: verify
language: node_js
node_js:
- '8'
Expand Down
4 changes: 1 addition & 3 deletions integration_test/functions/src/database-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ export const databaseTests: any = functions.database
.it('should have refs resources', (change, context) =>
expectEq(
context.resource.name,
`projects/_/instances/${process.env.GCLOUD_PROJECT}/refs/dbTests/${
context.params.testId
}/start`
`projects/_/instances/${process.env.GCLOUD_PROJECT}/refs/dbTests/${context.params.testId}/start`
)
)

Expand Down
4 changes: 1 addition & 3 deletions integration_test/functions/src/firestore-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export const firestoreTests: any = functions
.it('should have well-formatted resource', (snap, context) =>
expectEq(
context.resource.name,
`projects/${
process.env.GCLOUD_PROJECT
}/databases/(default)/documents/tests/${context.params.documentId}`
`projects/${process.env.GCLOUD_PROJECT}/databases/(default)/documents/tests/${context.params.documentId}`
)
)

Expand Down
8 changes: 2 additions & 6 deletions integration_test/functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ function callScheduleTrigger(functionName: string, region: string) {
{
method: 'POST',
host: 'cloudscheduler.googleapis.com',
path: `projects/${
firebaseConfig.projectId
}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
path: `projects/${firebaseConfig.projectId}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
headers: {
'Content-Type': 'application/json',
},
Expand Down Expand Up @@ -199,9 +197,7 @@ export const integrationTests: any = functions
resp
.status(500)
.send(
`FAIL - details at https://${
process.env.GCLOUD_PROJECT
}.firebaseio.com/testRuns/${testId}`
`FAIL - details at https://${process.env.GCLOUD_PROJECT}.firebaseio.com/testRuns/${testId}`
);
});
});
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
"build:pack": "rm -rf lib && npm install && tsc -p tsconfig.release.json && npm pack",
"build:release": "npm install --production && npm install typescript firebase-admin && tsc -p tsconfig.release.json",
"build": "tsc -p tsconfig.release.json",
"format": "prettier --write '**/*.ts'",
"lint": "tslint --project tsconfig.json --config tslint.json",
"posttest": "npm run format",
"format": "prettier --check '**/*.ts'",
"format:fix": "prettier --write '**/*.ts'",
"lint": "tslint --config tslint.json --project tsconfig.json ",
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
"test": "mocha -r ts-node/register ./spec/index.spec.ts"
},
"dependencies": {
Expand Down Expand Up @@ -58,6 +59,7 @@
"sinon": "^7.3.2",
"ts-node": "^8.2.0",
"tslint": "^5.17.0",
"tslint-config-prettier": "^1.18.0",
"tslint-no-unused-expression-chai": "^0.1.4",
"tslint-plugin-prettier": "^2.0.0",
"typescript": "^3.5.1"
Expand Down
2 changes: 1 addition & 1 deletion spec/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import { expect } from 'chai';
import * as firebase from 'firebase-admin';

import { Resolver } from 'dns';
import { CloudFunction, Event, EventContext } from '../../src/cloud-functions';
import * as functions from '../../src/index';
import * as auth from '../../src/providers/auth';
import { Resolver } from 'dns';

describe('Auth Functions', () => {
const event: Event = {
Expand Down
8 changes: 4 additions & 4 deletions src/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import * as _ from 'lodash';
import * as firebase from 'firebase-admin';
import * as _ from 'lodash';
import { firebaseConfig } from './config';

export function apps(): apps.Apps {
Expand Down Expand Up @@ -65,7 +65,7 @@ export namespace apps {

_appAlive(appName: string): boolean {
try {
let app = firebase.app(appName);
const app = firebase.app(appName);
return !_.get(app, 'isDeleted_');
} catch (e) {
return false;
Expand All @@ -83,15 +83,15 @@ export namespace apps {
}

retain() {
let increment = (n?: number) => {
const increment = (n?: number) => {
return (n || 0) + 1;
};
// Increment counter for admin because function might use event.data.ref
_.update(this._refCounter, '__admin__', increment);
}

release() {
let decrement = (n: number) => {
const decrement = (n: number) => {
return n - 1;
};
return delay(garbageCollectionInterval).then(() => {
Expand Down
28 changes: 14 additions & 14 deletions src/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ export namespace Change {
after: any,
fieldMask: string
) {
let before = _.assign({}, after);
let masks = fieldMask.split(',');
const before = _.assign({}, after);
const masks = fieldMask.split(',');
_.forEach(masks, (mask) => {
const val = _.get(sparseBefore, mask);
if (typeof val === 'undefined') {
Expand Down Expand Up @@ -239,17 +239,17 @@ export function makeCloudFunction<EventData>({
opts = {},
labels = {},
}: MakeCloudFunctionArgs<EventData>): CloudFunction<EventData> {
let cloudFunction: any = (data: any, context: any) => {
const cloudFunction: any = (data: any, context: any) => {
if (legacyEventType && context.eventType === legacyEventType) {
// v1beta1 event flow has different format for context, transform them to new format.
context.eventType = provider + '.' + eventType;
context.resource = {
service: service,
service,
name: context.resource,
};
}

let event: Event = {
const event: Event = {
data,
context,
};
Expand Down Expand Up @@ -305,7 +305,7 @@ export function makeCloudFunction<EventData>({
return {};
}

let trigger: any = _.assign(optsToTrigger(opts), {
const trigger: any = _.assign(optsToTrigger(opts), {
eventTrigger: {
resource: triggerResource(),
eventType: legacyEventType || provider + '.' + eventType,
Expand Down Expand Up @@ -335,15 +335,15 @@ function _makeParams(
// In unit testing, `resource` may be unpopulated for a test event.
return {};
}
let triggerResource = triggerResourceGetter();
let wildcards = triggerResource.match(WILDCARD_REGEX);
let params: { [option: string]: any } = {};
const triggerResource = triggerResourceGetter();
const wildcards = triggerResource.match(WILDCARD_REGEX);
const params: { [option: string]: any } = {};
if (wildcards) {
let triggerResourceParts = _.split(triggerResource, '/');
let eventResourceParts = _.split(context.resource.name, '/');
const triggerResourceParts = _.split(triggerResource, '/');
const eventResourceParts = _.split(context.resource.name, '/');
_.forEach(wildcards, (wildcard) => {
let wildcardNoBraces = wildcard.slice(1, -1);
let position = _.indexOf(triggerResourceParts, wildcard);
const wildcardNoBraces = wildcard.slice(1, -1);
const position = _.indexOf(triggerResourceParts, wildcard);
params[wildcardNoBraces] = eventResourceParts[position];
});
}
Expand Down Expand Up @@ -371,7 +371,7 @@ function _detectAuthType(event: Event) {
}

export function optsToTrigger(opts: DeploymentOptions) {
let trigger: any = {};
const trigger: any = {};
if (opts.regions) {
trigger.regions = opts.regions;
}
Expand Down
6 changes: 4 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export function config(): config.Config {
export namespace config {
// Config type is usable as a object (dot notation allowed), and firebase
// property will also code complete.
export type Config = { [key: string]: any };
export interface Config {
[key: string]: any;
}

/** @internal */
export let singleton: config.Config;
Expand Down Expand Up @@ -81,7 +83,7 @@ function init() {
}

try {
let path =
const path =
process.env.CLOUD_RUNTIME_CONFIG || '../../../.runtimeconfig.json';
const parsed = require(path);
delete parsed.firebase;
Expand Down
4 changes: 2 additions & 2 deletions src/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function dateToTimestampProto(timeString?: string) {
if (typeof timeString === 'undefined') {
return;
}
let date = new Date(timeString);
let seconds = Math.floor(date.getTime() / 1000);
const date = new Date(timeString);
const seconds = Math.floor(date.getTime() / 1000);
let nanos = 0;
if (timeString.length > 20) {
const nanoString = timeString.substring(20, timeString.length - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import * as _ from 'lodash';
import * as express from 'express';
import * as _ from 'lodash';

import { CloudFunction, EventContext, Schedule } from './cloud-functions';
import * as analytics from './providers/analytics';
import * as auth from './providers/auth';
import * as crashlytics from './providers/crashlytics';
Expand All @@ -32,7 +33,6 @@ import * as https from './providers/https';
import * as pubsub from './providers/pubsub';
import * as remoteConfig from './providers/remoteConfig';
import * as storage from './providers/storage';
import { CloudFunction, EventContext, Schedule } from './cloud-functions';

/**
* List of all regions supported by Cloud Functions.
Expand Down
2 changes: 1 addition & 1 deletion src/handler-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import * as express from 'express';

import { apps } from './apps';
import { CloudFunction, EventContext, HttpsFunction } from './cloud-functions';
import * as analytics from './providers/analytics';
import * as auth from './providers/auth';
import * as crashlytics from './providers/crashlytics';
Expand All @@ -32,7 +33,6 @@ import * as https from './providers/https';
import * as pubsub from './providers/pubsub';
import * as remoteConfig from './providers/remoteConfig';
import * as storage from './providers/storage';
import { CloudFunction, EventContext, HttpsFunction } from './cloud-functions';

export class HandlerBuilder {
constructor() {}
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import * as analytics from './providers/analytics';
import * as auth from './providers/auth';

import * as apps from './apps';
import { handler } from './handler-builder';
import * as crashlytics from './providers/crashlytics';
import * as database from './providers/database';
import * as firestore from './providers/firestore';
import * as https from './providers/https';
import * as pubsub from './providers/pubsub';
import * as remoteConfig from './providers/remoteConfig';
import * as storage from './providers/storage';
import { handler } from './handler-builder';
import { setup } from './setup';

var app = apps.apps();
const app = apps.apps();

export {
analytics,
Expand Down
16 changes: 8 additions & 8 deletions src/providers/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import * as _ from 'lodash';

import {
makeCloudFunction,
CloudFunction,
Event,
EventContext,
makeCloudFunction,
} from '../cloud-functions';
import { DeploymentOptions } from '../function-builder';

Expand Down Expand Up @@ -141,7 +141,7 @@ export class AnalyticsEvent {
this.params = {}; // In case of absent field, show empty (not absent) map.
if (wireFormat.eventDim && wireFormat.eventDim.length > 0) {
// If there's an eventDim, there'll always be exactly one.
let eventDim = wireFormat.eventDim[0];
const eventDim = wireFormat.eventDim[0];
copyField(eventDim, this, 'name');
copyField(eventDim, this, 'params', (p) => _.mapValues(p, unwrapValue));
copyFieldTo(eventDim, this, 'valueInUsd', 'valueInUSD');
Expand Down Expand Up @@ -415,7 +415,7 @@ function copyField<T, K extends keyof T>(
}

function copyFields<T, K extends keyof T>(from: any, to: T, fields: K[]): void {
for (let field of fields) {
for (const field of fields) {
copyField(from, to, field);
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ function copyFields<T, K extends keyof T>(from: any, to: T, fields: K[]): void {
// method always returns a string, similarly to avoid loss of precision, unlike the less-conservative
// 'unwrapValue' method just below.
function unwrapValueAsString(wrapped: any): string {
let key: string = _.keys(wrapped)[0];
const key: string = _.keys(wrapped)[0];
return _.toString(wrapped[key]);
}
// Ditto as the method above, but returning the values in the idiomatic JavaScript type (string for strings,
Expand All @@ -468,8 +468,8 @@ function unwrapValueAsString(wrapped: any): string {
// in precision for int64 fields, so use with care.
const xValueNumberFields = ['intValue', 'floatValue', 'doubleValue'];
function unwrapValue(wrapped: any): any {
let key: string = _.keys(wrapped)[0];
let value: string = unwrapValueAsString(wrapped);
const key: string = _.keys(wrapped)[0];
const value: string = unwrapValueAsString(wrapped);
return _.includes(xValueNumberFields, key) ? _.toNumber(value) : value;
}

Expand All @@ -483,7 +483,7 @@ function copyTimestampToMillis<T, K extends keyof T>(
toName: K
) {
if (from[fromName] !== undefined) {
to[toName] = <any>_.round(from[fromName] / 1000);
to[toName] = _.round(from[fromName] / 1000) as any;
}
}

Expand All @@ -497,6 +497,6 @@ function copyTimestampToString<T, K extends keyof T>(
toName: K
) {
if (from[fromName] !== undefined) {
to[toName] = <any>new Date(from[fromName] / 1000).toISOString();
to[toName] = new Date(from[fromName] / 1000).toISOString() as any;
}
}
14 changes: 7 additions & 7 deletions src/providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import * as firebase from 'firebase-admin';
import * as _ from 'lodash';
import {
makeCloudFunction,
CloudFunction,
EventContext,
Event,
EventContext,
makeCloudFunction,
} from '../cloud-functions';
import * as firebase from 'firebase-admin';
import * as _ from 'lodash';
import { DeploymentOptions } from '../function-builder';

/** @internal */
Expand Down Expand Up @@ -120,7 +120,7 @@ export function userRecordConstructor(
wireData: Object
): firebase.auth.UserRecord {
// Falsey values from the wire format proto get lost when converted to JSON, this adds them back.
let falseyValues: any = {
const falseyValues: any = {
email: null,
emailVerified: false,
displayName: null,
Expand All @@ -133,9 +133,9 @@ export function userRecordConstructor(
passwordHash: null,
tokensValidAfterTime: null,
};
let record = _.assign({}, falseyValues, wireData);
const record = _.assign({}, falseyValues, wireData);

let meta = _.get(record, 'metadata');
const meta = _.get(record, 'metadata');
if (meta) {
_.set(
record,
Expand Down
Loading