diff --git a/integration_test/firebase.json b/integration_test/firebase.json index c0a1756fa..5ab884ea2 100644 --- a/integration_test/firebase.json +++ b/integration_test/firebase.json @@ -10,4 +10,4 @@ "source": "functions", "codebase": "integration-tests" } -} \ No newline at end of file +} diff --git a/spec/v1/cloud-functions.spec.ts b/spec/v1/cloud-functions.spec.ts index 8f445efb3..cec3b7790 100644 --- a/spec/v1/cloud-functions.spec.ts +++ b/spec/v1/cloud-functions.spec.ts @@ -41,7 +41,7 @@ describe('makeCloudFunction', () => { legacyEventType: 'providers/provider/eventTypes/event', }; - it('should put a __trigger/__endpoint on the returned CloudFunction', () => { + it('should put a __endpoint on the returned CloudFunction', () => { const cf = makeCloudFunction({ provider: 'mock.provider', eventType: 'mock.event', @@ -50,14 +50,6 @@ describe('makeCloudFunction', () => { handler: () => null, }); - expect(cf.__trigger).to.deep.equal({ - eventTrigger: { - eventType: 'mock.provider.mock.event', - resource: 'resource', - service: 'service', - }, - }); - expect(cf.__endpoint).to.deep.equal({ platform: 'gcfv1', eventTrigger: { @@ -71,17 +63,9 @@ describe('makeCloudFunction', () => { }); }); - it('should have legacy event type in __trigger/__endpoint if provided', () => { + it('should have legacy event type in __endpoint if provided', () => { const cf = makeCloudFunction(cloudFunctionArgs); - expect(cf.__trigger).to.deep.equal({ - eventTrigger: { - eventType: 'providers/provider/eventTypes/event', - resource: 'resource', - service: 'service', - }, - }); - expect(cf.__endpoint).to.deep.equal({ platform: 'gcfv1', eventTrigger: { diff --git a/spec/v1/function-builder.spec.ts b/spec/v1/function-builder.spec.ts index 8df5d4413..caf0332e0 100644 --- a/spec/v1/function-builder.spec.ts +++ b/spec/v1/function-builder.spec.ts @@ -39,7 +39,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); + expect(fn.__endpoint.region).to.deep.equal(['us-east1']); }); it('should allow multiple supported regions to be set', () => { @@ -48,7 +48,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.regions).to.deep.equal(['us-east1', 'us-central1']); + expect(fn.__endpoint.region).to.deep.equal(['us-east1', 'us-central1']); }); it('should allow all supported regions to be set', () => { @@ -66,7 +66,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.regions).to.deep.equal([ + expect(fn.__endpoint.region).to.deep.equal([ 'us-central1', 'us-east1', 'us-east4', @@ -88,9 +88,9 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__trigger.failurePolicy).to.deep.equal({ retry: {} }); + expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); + expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); + expect(fn.__endpoint.eventTrigger.retry).to.deep.equal(true); }); it("should apply a default failure policy if it's aliased with `true`", () => { @@ -103,7 +103,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.failurePolicy).to.deep.equal({ retry: {} }); + expect(fn.__endpoint.eventTrigger.retry).to.deep.equal(true); }); it('should allow both supported region and valid runtime options to be set', () => { @@ -116,9 +116,9 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.regions).to.deep.equal(['europe-west2']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); + expect(fn.__endpoint.region).to.deep.equal(['europe-west2']); + expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); + expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); }); it('should allow both valid runtime options and supported region to be set in reverse order', () => { @@ -131,9 +131,9 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.regions).to.deep.equal(['europe-west1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); + expect(fn.__endpoint.region).to.deep.equal(['europe-west1']); + expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); + expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); }); it('should fail if supported region but invalid runtime options are set (reverse order)', () => { @@ -205,7 +205,7 @@ describe('FunctionBuilder', () => { .runWith({ ingressSettings: 'ALLOW_INTERNAL_ONLY' }) .https.onRequest(() => {}); - expect(fn.__trigger.ingressSettings).to.equal('ALLOW_INTERNAL_ONLY'); + expect(fn.__endpoint.ingressSettings).to.equal('ALLOW_INTERNAL_ONLY'); }); it('should throw an error if user chooses an invalid ingressSettings', () => { @@ -229,7 +229,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.vpcConnector).to.equal('test-connector'); + expect(fn.__endpoint.vpc.connector).to.equal('test-connector'); }); it('should allow a vpcConnectorEgressSettings to be set', () => { @@ -241,9 +241,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.vpcConnectorEgressSettings).to.equal( - 'PRIVATE_RANGES_ONLY' - ); + expect(fn.__endpoint.vpc.egressSettings).to.equal('PRIVATE_RANGES_ONLY'); }); it('should throw an error if user chooses an invalid vpcConnectorEgressSettings', () => { @@ -269,12 +267,11 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.serviceAccountEmail).to.equal(serviceAccount); + expect(fn.__endpoint.serviceAccountEmail).to.equal(serviceAccount); }); it('should allow a serviceAccount to be set with generated service account email', () => { const serviceAccount = 'test-service-account@'; - const projectId = process.env.GCLOUD_PROJECT; const fn = functions .runWith({ serviceAccount, @@ -282,9 +279,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.serviceAccountEmail).to.equal( - `test-service-account@${projectId}.iam.gserviceaccount.com` - ); + expect(fn.__endpoint.serviceAccountEmail).to.equal(`test-service-account@`); }); it('should set a null serviceAccountEmail if service account is set to `default`', () => { @@ -296,7 +291,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.serviceAccountEmail).to.be.null; + expect(fn.__endpoint.serviceAccountEmail).to.equal('default'); }); it('should throw an error if serviceAccount is set to an invalid value', () => { @@ -317,7 +312,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(4096); + expect(fn.__endpoint.availableMemoryMb).to.deep.equal(4096); }); it('should allow labels to be set', () => { @@ -330,7 +325,7 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.labels).to.deep.equal({ + expect(fn.__endpoint.labels).to.deep.equal({ 'valid-key': 'valid-value', }); }); @@ -487,7 +482,11 @@ describe('FunctionBuilder', () => { .auth.user() .onCreate((user) => user); - expect(fn.__trigger.secrets).to.deep.equal(secrets); + expect(fn.__endpoint.secretEnvironmentVariables).to.deep.equal([ + { + key: 'API_KEY', + }, + ]); }); it('should throw error given secrets expressed with full resource name', () => { diff --git a/spec/v1/providers/analytics.spec.ts b/spec/v1/providers/analytics.spec.ts index 5dc3c29fb..f1fa2162f 100644 --- a/spec/v1/providers/analytics.spec.ts +++ b/spec/v1/providers/analytics.spec.ts @@ -47,10 +47,6 @@ describe('Analytics Functions', () => { .analytics.event('event') .onLog((event) => event); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); @@ -60,15 +56,6 @@ describe('Analytics Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const cloudFunction = analytics.event('first_open').onLog(() => null); - expect(cloudFunction.__trigger).to.deep.equal({ - eventTrigger: { - eventType: - 'providers/google.firebase.analytics/eventTypes/event.log', - resource: 'projects/project1/events/first_open', - service: 'app-measurement.com', - }, - }); - expect(cloudFunction.__endpoint).to.deep.equal({ platform: 'gcfv1', eventTrigger: { @@ -322,11 +309,10 @@ describe('Analytics Functions', () => { describe('handler namespace', () => { describe('#onLog', () => { - it('should return an empty trigger/endpoint', () => { + it('should return an empty endpoint', () => { const cloudFunction = functions.handler.analytics.event.onLog( () => null ); - expect(cloudFunction.__trigger).to.deep.equal({}); expect(cloudFunction.__endpoint).to.be.undefined; }); @@ -369,15 +355,15 @@ describe('Analytics Functions', () => { }); describe('process.env.GCLOUD_PROJECT not set', () => { - it('should not throw if __trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => analytics.event('event').onLog(() => null)).to.not.throw( Error ); }); - it('should throw when trigger is accessed', () => { + it('should throw when __endpoint is accessed', () => { expect( - () => analytics.event('event').onLog(() => null).__trigger + () => analytics.event('event').onLog(() => null).__endpoint ).to.throw(Error); }); diff --git a/spec/v1/providers/auth.spec.ts b/spec/v1/providers/auth.spec.ts index 0a1560596..d440866e4 100644 --- a/spec/v1/providers/auth.spec.ts +++ b/spec/v1/providers/auth.spec.ts @@ -50,16 +50,6 @@ describe('Auth Functions', () => { }; describe('AuthBuilder', () => { - function expectedTrigger(project: string, eventType: string) { - return { - eventTrigger: { - resource: `projects/${project}`, - eventType: `providers/firebase.auth/eventTypes/${eventType}`, - service: 'firebaseauth.googleapis.com', - }, - }; - } - function expectedEndpoint(project: string, eventType: string) { return { platform: 'gcfv1', @@ -98,9 +88,9 @@ describe('Auth Functions', () => { .auth.user() .onCreate(() => null); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); + expect(fn.__endpoint.region).to.deep.equal(['us-east1']); + expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); + expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); @@ -111,10 +101,6 @@ describe('Auth Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const cloudFunction = auth.user().onCreate(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(project, 'user.create') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(project, 'user.create') ); @@ -125,10 +111,6 @@ describe('Auth Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const cloudFunction = auth.user().onDelete(handler); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(project, 'user.delete') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(project, 'user.delete') ); @@ -139,17 +121,6 @@ describe('Auth Functions', () => { it('should create the function without options', () => { const fn = auth.user().beforeCreate((u, c) => Promise.resolve()); - expect(fn.__trigger).to.deep.equal({ - labels: {}, - blockingTrigger: { - eventType: 'providers/cloud.auth/eventTypes/user.beforeCreate', - options: { - accessToken: false, - idToken: false, - refreshToken: false, - }, - }, - }); expect(fn.__endpoint).to.deep.equal({ platform: 'gcfv1', labels: {}, @@ -185,20 +156,6 @@ describe('Auth Functions', () => { }) .beforeCreate((u, c) => Promise.resolve()); - expect(fn.__trigger).to.deep.equal({ - labels: {}, - regions: ['us-east1'], - availableMemoryMb: 256, - timeout: '90s', - blockingTrigger: { - eventType: 'providers/cloud.auth/eventTypes/user.beforeCreate', - options: { - accessToken: true, - idToken: false, - refreshToken: false, - }, - }, - }); expect(fn.__endpoint).to.deep.equal({ platform: 'gcfv1', labels: {}, @@ -227,17 +184,6 @@ describe('Auth Functions', () => { it('should create the function without options', () => { const fn = auth.user().beforeSignIn((u, c) => Promise.resolve()); - expect(fn.__trigger).to.deep.equal({ - labels: {}, - blockingTrigger: { - eventType: 'providers/cloud.auth/eventTypes/user.beforeSignIn', - options: { - accessToken: false, - idToken: false, - refreshToken: false, - }, - }, - }); expect(fn.__endpoint).to.deep.equal({ platform: 'gcfv1', labels: {}, @@ -273,20 +219,6 @@ describe('Auth Functions', () => { }) .beforeSignIn((u, c) => Promise.resolve()); - expect(fn.__trigger).to.deep.equal({ - labels: {}, - regions: ['us-east1'], - availableMemoryMb: 256, - timeout: '90s', - blockingTrigger: { - eventType: 'providers/cloud.auth/eventTypes/user.beforeSignIn', - options: { - accessToken: true, - idToken: false, - refreshToken: false, - }, - }, - }); expect(fn.__endpoint).to.deep.equal({ platform: 'gcfv1', labels: {}, @@ -337,11 +269,6 @@ describe('Auth Functions', () => { describe('handler namespace', () => { describe('#onCreate', () => { - it('should return an empty trigger', () => { - const cloudFunction = functions.handler.auth.user.onCreate(() => null); - expect(cloudFunction.__trigger).to.deep.equal({}); - }); - it('should return an empty endpoint', () => { const cloudFunction = functions.handler.auth.user.onCreate(() => null); expect(cloudFunction.__endpoint).to.be.undefined; @@ -353,11 +280,6 @@ describe('Auth Functions', () => { (data: UserRecord) => data ); - it('should return an empty trigger', () => { - const cloudFunction = functions.handler.auth.user.onDelete(() => null); - expect(cloudFunction.__trigger).to.deep.equal({}); - }); - it('should return an empty endpoint', () => { const cloudFunction = functions.handler.auth.user.onDelete(() => null); expect(cloudFunction.__endpoint).to.be.undefined; @@ -379,14 +301,10 @@ describe('Auth Functions', () => { }); describe('process.env.GCLOUD_PROJECT not set', () => { - it('should not throw if __trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => auth.user().onCreate(() => null)).to.not.throw(Error); }); - it('should throw when trigger is accessed', () => { - expect(() => auth.user().onCreate(() => null).__trigger).to.throw(Error); - }); - it('should throw when endpoint is accessed', () => { expect(() => auth.user().onCreate(() => null).__endpoint).to.throw(Error); }); diff --git a/spec/v1/providers/database.spec.ts b/spec/v1/providers/database.spec.ts index f8076dc52..ac1d80e89 100644 --- a/spec/v1/providers/database.spec.ts +++ b/spec/v1/providers/database.spec.ts @@ -31,16 +31,6 @@ describe('Database Functions', () => { describe('DatabaseBuilder', () => { // TODO add tests for building a data or change based on the type of operation - function expectedTrigger(resource: string, eventType: string) { - return { - eventTrigger: { - resource, - eventType: `providers/google.firebase.database/eventTypes/${eventType}`, - service: 'firebaseio.com', - }, - }; - } - function expectedEndpoint(resource: string, eventType: string) { return { platform: 'gcfv1', @@ -77,9 +67,9 @@ describe('Database Functions', () => { .database.ref('/') .onCreate((snap) => snap); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); + expect(fn.__endpoint.region).to.deep.equal(['us-east1']); + expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); + expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); @@ -87,16 +77,9 @@ describe('Database Functions', () => { }); describe('#onWrite()', () => { - it('should return a trigger/endpoint with appropriate values', () => { + it('should return a endpoint with appropriate values', () => { const func = database.ref('foo').onWrite(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger( - 'projects/_/instances/subdomain/refs/foo', - 'ref.write' - ) - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint( 'projects/_/instances/subdomain/refs/foo', @@ -111,10 +94,6 @@ describe('Database Functions', () => { .ref('foo') .onWrite(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger('projects/_/instances/custom/refs/foo', 'ref.write') - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint('projects/_/instances/custom/refs/foo', 'ref.write') ); @@ -148,13 +127,6 @@ describe('Database Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const func = database.ref('foo').onCreate(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger( - 'projects/_/instances/subdomain/refs/foo', - 'ref.create' - ) - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint( 'projects/_/instances/subdomain/refs/foo', @@ -169,10 +141,6 @@ describe('Database Functions', () => { .ref('foo') .onCreate(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger('projects/_/instances/custom/refs/foo', 'ref.create') - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint('projects/_/instances/custom/refs/foo', 'ref.create') ); @@ -207,13 +175,6 @@ describe('Database Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const func = database.ref('foo').onUpdate(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger( - 'projects/_/instances/subdomain/refs/foo', - 'ref.update' - ) - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint( 'projects/_/instances/subdomain/refs/foo', @@ -228,10 +189,6 @@ describe('Database Functions', () => { .ref('foo') .onUpdate(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger('projects/_/instances/custom/refs/foo', 'ref.update') - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint('projects/_/instances/custom/refs/foo', 'ref.update') ); @@ -266,13 +223,6 @@ describe('Database Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const func = database.ref('foo').onDelete(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger( - 'projects/_/instances/subdomain/refs/foo', - 'ref.delete' - ) - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint( 'projects/_/instances/subdomain/refs/foo', @@ -287,10 +237,6 @@ describe('Database Functions', () => { .ref('foo') .onDelete(() => null); - expect(func.__trigger).to.deep.equal( - expectedTrigger('projects/_/instances/custom/refs/foo', 'ref.delete') - ); - expect(func.__endpoint).to.deep.equal( expectedEndpoint('projects/_/instances/custom/refs/foo', 'ref.delete') ); @@ -324,9 +270,8 @@ describe('Database Functions', () => { describe('handler namespace', () => { describe('#onWrite()', () => { - it('correctly sets trigger to {}', () => { + it('correctly sets __endpoint to undefind', () => { const cf = functions.handler.database.ref.onWrite(() => null); - expect(cf.__trigger).to.deep.equal({}); expect(cf.__endpoint).to.be.undefined; }); @@ -334,7 +279,6 @@ describe('Database Functions', () => { const func = functions.handler.database.instance.ref.onWrite( () => null ); - expect(func.__trigger).to.deep.equal({}); expect(func.__endpoint).to.be.undefined; }); @@ -364,9 +308,8 @@ describe('Database Functions', () => { }); describe('#onCreate()', () => { - it('correctly sets trigger to {}', () => { + it('correctly sets endpoint to undefined', () => { const cf = functions.handler.database.ref.onCreate(() => null); - expect(cf.__trigger).to.deep.equal({}); expect(cf.__endpoint).to.be.undefined; }); @@ -374,7 +317,6 @@ describe('Database Functions', () => { const func = functions.handler.database.instance.ref.onCreate( () => null ); - expect(func.__trigger).to.deep.equal({}); expect(func.__endpoint).to.be.undefined; }); @@ -403,9 +345,8 @@ describe('Database Functions', () => { }); describe('#onUpdate()', () => { - it('correctly sets trigger to {}', () => { + it('correctly sets endpoint to undefined', () => { const cf = functions.handler.database.ref.onUpdate(() => null); - expect(cf.__trigger).to.deep.equal({}); expect(cf.__endpoint).to.be.undefined; }); @@ -413,7 +354,6 @@ describe('Database Functions', () => { const func = functions.handler.database.instance.ref.onUpdate( () => null ); - expect(func.__trigger).to.deep.equal({}); expect(func.__endpoint).to.be.undefined; }); @@ -442,9 +382,8 @@ describe('Database Functions', () => { }); describe('#onDelete()', () => { - it('correctly sets trigger to {}', () => { + it('correctly sets endpoint to undefined', () => { const cf = functions.handler.database.ref.onDelete(() => null); - expect(cf.__trigger).to.deep.equal({}); expect(cf.__endpoint).to.be.undefined; }); @@ -452,7 +391,6 @@ describe('Database Functions', () => { const func = functions.handler.database.instance.ref.onDelete( () => null ); - expect(func.__trigger).to.deep.equal({}); expect(func.__endpoint).to.be.undefined; }); @@ -483,18 +421,12 @@ describe('Database Functions', () => { }); describe('process.env.FIREBASE_CONFIG not set', () => { - it('should not throw if __trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => database.ref('/path').onWrite(() => null)).to.not.throw( Error ); }); - it('should throw when trigger is accessed', () => { - expect( - () => database.ref('/path').onWrite(() => null).__trigger - ).to.throw(Error); - }); - it('should throw when endpoint is accessed', () => { expect( () => database.ref('/path').onWrite(() => null).__endpoint diff --git a/spec/v1/providers/firestore.spec.ts b/spec/v1/providers/firestore.spec.ts index 739b8719e..2761761c0 100644 --- a/spec/v1/providers/firestore.spec.ts +++ b/spec/v1/providers/firestore.spec.ts @@ -93,16 +93,6 @@ describe('Firestore Functions', () => { } describe('document builders and event types', () => { - function expectedTrigger(resource: string, eventType: string) { - return { - eventTrigger: { - resource, - eventType: `providers/cloud.firestore/eventTypes/${eventType}`, - service: 'firestore.googleapis.com', - }, - }; - } - function expectedEndpoint(resource: string, eventType: string) { return { platform: 'gcfv1', @@ -132,10 +122,6 @@ describe('Firestore Functions', () => { .document('users/{uid}') .onWrite(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(resource, 'document.write') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(resource, 'document.write') ); @@ -149,10 +135,6 @@ describe('Firestore Functions', () => { .document('users/{uid}') .onWrite(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(resource, 'document.write') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(resource, 'document.write') ); @@ -165,10 +147,6 @@ describe('Firestore Functions', () => { .document('users/{uid}') .onWrite(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(resource, 'document.write') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(resource, 'document.write') ); @@ -183,10 +161,6 @@ describe('Firestore Functions', () => { .document('users/{uid}') .onWrite(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(resource, 'document.write') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(resource, 'document.write') ); @@ -202,10 +176,6 @@ describe('Firestore Functions', () => { .firestore.document('doc') .onCreate((snap) => snap); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); @@ -213,18 +183,12 @@ describe('Firestore Functions', () => { }); describe('process.env.GCLOUD_PROJECT not set', () => { - it('should not throw if __trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => firestore.document('input').onCreate(() => null) ).to.not.throw(Error); }); - it('should throw when trigger is accessed', () => { - expect( - () => firestore.document('input').onCreate(() => null).__trigger - ).to.throw(Error); - }); - it('should throw when endpoint is accessed', () => { expect( () => firestore.document('input').onCreate(() => null).__endpoint @@ -322,7 +286,7 @@ describe('Firestore Functions', () => { delete process.env.GCLOUD_PROJECT; }); - it('constructs correct data type and sets trigger to {} on "document.write" events', () => { + it('constructs correct data type on "document.write" events', () => { const testFunction = functions.handler.firestore.document.onWrite( (change, context) => { expect(change.before.data()).to.deep.equal({ @@ -335,7 +299,6 @@ describe('Firestore Functions', () => { return true; // otherwise will get warning about returning undefined } ); - expect(testFunction.__trigger).to.deep.equal({}); const event = constructEvent( createOldValue(), createValue(), @@ -344,7 +307,7 @@ describe('Firestore Functions', () => { return testFunction(event.data, event.context); }).timeout(5000); - it('constructs correct data type and sets trigger to {} on "document.create" events', () => { + it('constructs correct data type on "document.create" events', () => { const testFunction = functions.handler.firestore.document.onCreate( (data, context) => { expect(data.data()).to.deep.equal({ key1: true, key2: 123 }); @@ -352,12 +315,11 @@ describe('Firestore Functions', () => { return true; // otherwise will get warning about returning undefined } ); - expect(testFunction.__trigger).to.deep.equal({}); const event = constructEvent({}, createValue(), 'document.create'); return testFunction(event.data, event.context); }).timeout(5000); - it('constructs correct data type and sets trigger to {} on "document.update" events', () => { + it('constructs correct data type on "document.update" events', () => { const testFunction = functions.handler.firestore.document.onUpdate( (change) => { expect(change.before.data()).to.deep.equal({ @@ -370,7 +332,6 @@ describe('Firestore Functions', () => { return true; // otherwise will get warning about returning undefined } ); - expect(testFunction.__trigger).to.deep.equal({}); const event = constructEvent( createOldValue(), createValue(), @@ -379,7 +340,7 @@ describe('Firestore Functions', () => { return testFunction(event.data, event.context); }).timeout(5000); - it('constructs correct data type and sets trigger to {} on "document.delete" events', () => { + it('constructs correct data type on "document.delete" events', () => { const testFunction = functions.handler.firestore.document.onDelete( (data, context) => { expect(data.data()).to.deep.equal({ key1: false, key2: 111 }); @@ -388,7 +349,6 @@ describe('Firestore Functions', () => { } ); const event = constructEvent(createOldValue(), {}, 'document.delete'); - expect(testFunction.__trigger).to.deep.equal({}); return testFunction(event.data, event.context); }).timeout(5000); }); diff --git a/spec/v1/providers/https.spec.ts b/spec/v1/providers/https.spec.ts index a8cb72f55..b1a9cfa6b 100644 --- a/spec/v1/providers/https.spec.ts +++ b/spec/v1/providers/https.spec.ts @@ -36,7 +36,6 @@ describe('CloudHttpsBuilder', () => { const result = https.onRequest((req, resp) => { resp.send(200); }); - expect(result.__trigger).to.deep.equal({ httpsTrigger: {} }); expect(result.__endpoint).to.deep.equal({ platform: 'gcfv1', httpsTrigger: {}, @@ -53,11 +52,6 @@ describe('CloudHttpsBuilder', () => { }) .https.onRequest(() => null); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__trigger.httpsTrigger.invoker).to.deep.equal(['private']); - expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); @@ -72,7 +66,6 @@ describe('handler namespace', () => { const result = functions.handler.https.onRequest((req, res) => { res.send(200); }); - expect(result.__trigger).to.deep.equal({}); expect(result.__endpoint).to.be.undefined; }); }); @@ -80,7 +73,6 @@ describe('handler namespace', () => { describe('#onCall', () => { it('should return an empty trigger', () => { const result = functions.handler.https.onCall(() => null); - expect(result.__trigger).to.deep.equal({}); expect(result.__endpoint).to.be.undefined; }); }); @@ -92,11 +84,6 @@ describe('#onCall', () => { return 'response'; }); - expect(result.__trigger).to.deep.equal({ - httpsTrigger: {}, - labels: { 'deployment-callable': 'true' }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv1', callableTrigger: {}, @@ -113,10 +100,6 @@ describe('#onCall', () => { }) .https.onCall(() => null); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); diff --git a/spec/v1/providers/pubsub.spec.ts b/spec/v1/providers/pubsub.spec.ts index 67db7cd68..1809c84ec 100644 --- a/spec/v1/providers/pubsub.spec.ts +++ b/spec/v1/providers/pubsub.spec.ts @@ -82,10 +82,6 @@ describe('Pubsub Functions', () => { .pubsub.topic('toppy') .onPublish(() => null); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); @@ -96,14 +92,6 @@ describe('Pubsub Functions', () => { // Pick up project from process.env.GCLOUD_PROJECT const result = pubsub.topic('toppy').onPublish(() => null); - expect(result.__trigger).to.deep.equal({ - eventTrigger: { - eventType: 'google.pubsub.topic.publish', - resource: 'projects/project1/topics/toppy', - service: 'pubsub.googleapis.com', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv1', eventTrigger: { @@ -165,10 +153,6 @@ describe('Pubsub Functions', () => { .schedule('every 5 minutes') .onRun((context) => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - }); - expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', }); @@ -180,11 +164,6 @@ describe('Pubsub Functions', () => { .timeZone('America/New_York') .onRun((context) => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - timeZone: 'America/New_York', - }); - expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', timeZone: 'America/New_York', @@ -204,14 +183,6 @@ describe('Pubsub Functions', () => { .retryConfig(retryConfig) .onRun(() => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - retryConfig, - }); - expect(result.__trigger.labels).to.deep.equal({ - 'deployment-scheduled': 'true', - }); - expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', retryConfig, @@ -236,15 +207,6 @@ describe('Pubsub Functions', () => { .retryConfig(retryConfig) .onRun(() => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - retryConfig, - timeZone: 'America/New_York', - }); - expect(result.__trigger.labels).to.deep.equal({ - 'deployment-scheduled': 'true', - }); - expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', retryConfig, @@ -263,12 +225,6 @@ describe('Pubsub Functions', () => { }) .pubsub.schedule('every 5 minutes') .onRun(() => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - }); - expect(result.__trigger.regions).to.deep.equal(['us-east1']); - expect(result.__trigger.availableMemoryMb).to.deep.equal(256); - expect(result.__trigger.timeout).to.deep.equal('90s'); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', @@ -288,13 +244,6 @@ describe('Pubsub Functions', () => { .pubsub.schedule('every 5 minutes') .timeZone('America/New_York') .onRun(() => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - timeZone: 'America/New_York', - }); - expect(result.__trigger.regions).to.deep.equal(['us-east1']); - expect(result.__trigger.availableMemoryMb).to.deep.equal(256); - expect(result.__trigger.timeout).to.deep.equal('90s'); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', @@ -322,16 +271,6 @@ describe('Pubsub Functions', () => { .pubsub.schedule('every 5 minutes') .retryConfig(retryConfig) .onRun(() => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - retryConfig, - }); - expect(result.__trigger.labels).to.deep.equal({ - 'deployment-scheduled': 'true', - }); - expect(result.__trigger.regions).to.deep.equal(['us-east1']); - expect(result.__trigger.availableMemoryMb).to.deep.equal(256); - expect(result.__trigger.timeout).to.deep.equal('90s'); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', @@ -360,17 +299,6 @@ describe('Pubsub Functions', () => { .timeZone('America/New_York') .retryConfig(retryConfig) .onRun(() => null); - expect(result.__trigger.schedule).to.deep.equal({ - schedule: 'every 5 minutes', - timeZone: 'America/New_York', - retryConfig, - }); - expect(result.__trigger.labels).to.deep.equal({ - 'deployment-scheduled': 'true', - }); - expect(result.__trigger.regions).to.deep.equal(['us-east1']); - expect(result.__trigger.availableMemoryMb).to.deep.equal(256); - expect(result.__trigger.timeout).to.deep.equal('90s'); expect(result.__endpoint.scheduleTrigger).to.deep.equal({ schedule: 'every 5 minutes', @@ -389,7 +317,6 @@ describe('Pubsub Functions', () => { describe('#topic', () => { it('should return an empty trigger', () => { const result = functions.handler.pubsub.topic.onPublish(() => null); - expect(result.__trigger).to.deep.equal({}); expect(result.__endpoint).to.be.undefined; }); @@ -435,7 +362,7 @@ describe('Pubsub Functions', () => { describe('#schedule', () => { it('should return an empty trigger', () => { const result = functions.handler.pubsub.schedule.onRun(() => null); - expect(result.__trigger).to.deep.equal({}); + expect(result.__endpoint).to.be.undefined; }); it('should return a handler with a proper event context', () => { const raw = new Buffer('{"hello":"world"}', 'utf8').toString( @@ -470,18 +397,12 @@ describe('Pubsub Functions', () => { }); describe('process.env.GCLOUD_PROJECT not set', () => { - it('should not throw if __trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => pubsub.topic('toppy').onPublish(() => null)).to.not.throw( Error ); }); - it('should throw when trigger is accessed', () => { - expect( - () => pubsub.topic('toppy').onPublish(() => null).__trigger - ).to.throw(Error); - }); - it('should throw when endpoint is accessed', () => { expect( () => pubsub.topic('toppy').onPublish(() => null).__endpoint diff --git a/spec/v1/providers/remoteConfig.spec.ts b/spec/v1/providers/remoteConfig.spec.ts index a48709eff..f0367916e 100644 --- a/spec/v1/providers/remoteConfig.spec.ts +++ b/spec/v1/providers/remoteConfig.spec.ts @@ -56,14 +56,6 @@ describe('RemoteConfig Functions', () => { it('should have the correct trigger', () => { const cloudFunction = remoteConfig.onUpdate(() => null); - expect(cloudFunction.__trigger).to.deep.equal({ - eventTrigger: { - resource: 'projects/project1', - eventType: 'google.firebase.remoteconfig.update', - service: 'firebaseremoteconfig.googleapis.com', - }, - }); - expect(cloudFunction.__endpoint).to.deep.equal({ platform: 'gcfv1', eventTrigger: { @@ -86,10 +78,6 @@ describe('RemoteConfig Functions', () => { }) .remoteConfig.onUpdate(() => null); - expect(cloudFunction.__trigger.regions).to.deep.equal(['us-east1']); - expect(cloudFunction.__trigger.availableMemoryMb).to.deep.equal(256); - expect(cloudFunction.__trigger.timeout).to.deep.equal('90s'); - expect(cloudFunction.__endpoint.region).to.deep.equal(['us-east1']); expect(cloudFunction.__endpoint.availableMemoryMb).to.deep.equal(256); expect(cloudFunction.__endpoint.timeoutSeconds).to.deep.equal(90); @@ -143,7 +131,6 @@ describe('RemoteConfig Functions', () => { () => null ); - expect(cloudFunction.__trigger).to.deep.equal({}); expect(cloudFunction.__endpoint).to.be.undefined; }); diff --git a/spec/v1/providers/storage.spec.ts b/spec/v1/providers/storage.spec.ts index 247e0d877..12ff2b3bb 100644 --- a/spec/v1/providers/storage.spec.ts +++ b/spec/v1/providers/storage.spec.ts @@ -28,16 +28,6 @@ import * as storage from '../../../src/v1/providers/storage'; describe('Storage Functions', () => { describe('ObjectBuilder', () => { - function expectedTrigger(bucket: string, eventType: string) { - return { - eventTrigger: { - resource: `projects/_/buckets/${bucket}`, - eventType: `google.storage.object.${eventType}`, - service: 'storage.googleapis.com', - }, - }; - } - function expectedEndpoint(bucket: string, eventType: string) { return { platform: 'gcfv1', @@ -74,10 +64,6 @@ describe('Storage Functions', () => { .storage.object() .onArchive(() => null); - expect(fn.__trigger.regions).to.deep.equal(['us-east1']); - expect(fn.__trigger.availableMemoryMb).to.deep.equal(256); - expect(fn.__trigger.timeout).to.deep.equal('90s'); - expect(fn.__endpoint.region).to.deep.equal(['us-east1']); expect(fn.__endpoint.availableMemoryMb).to.deep.equal(256); expect(fn.__endpoint.timeoutSeconds).to.deep.equal(90); @@ -90,10 +76,6 @@ describe('Storage Functions', () => { .object() .onArchive(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger('bucky', 'archive') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'archive') ); @@ -102,10 +84,6 @@ describe('Storage Functions', () => { it('should use the default bucket when none is provided', () => { const cloudFunction = storage.object().onArchive(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(defaultBucket, 'archive') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(defaultBucket, 'archive') ); @@ -118,24 +96,12 @@ describe('Storage Functions', () => { ); const result = subjectQualified.onArchive(() => null); - expect(result.__trigger).to.deep.equal( - expectedTrigger('bucky', 'archive') - ); - expect(result.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'archive') ); }); it('should throw with improperly formatted buckets', () => { - expect( - () => - storage - .bucket('bad/bucket/format') - .object() - .onArchive(() => null).__trigger - ).to.throw(Error); - expect( () => storage @@ -181,10 +147,6 @@ describe('Storage Functions', () => { .object() .onDelete(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger('bucky', 'delete') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'delete') ); @@ -193,10 +155,6 @@ describe('Storage Functions', () => { it('should use the default bucket when none is provided', () => { const cloudFunction = storage.object().onDelete(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(defaultBucket, 'delete') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(defaultBucket, 'delete') ); @@ -209,10 +167,6 @@ describe('Storage Functions', () => { ); const result = subjectQualified.onDelete(() => null); - expect(result.__trigger).to.deep.equal( - expectedTrigger('bucky', 'delete') - ); - expect(result.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'delete') ); @@ -224,8 +178,6 @@ describe('Storage Functions', () => { .object() .onDelete(() => null); - expect(() => fn.__trigger).to.throw(Error); - expect(() => fn.__endpoint).to.throw(Error); }); @@ -265,10 +217,6 @@ describe('Storage Functions', () => { .object() .onFinalize(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger('bucky', 'finalize') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'finalize') ); @@ -277,10 +225,6 @@ describe('Storage Functions', () => { it('should use the default bucket when none is provided', () => { const cloudFunction = storage.object().onFinalize(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(defaultBucket, 'finalize') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(defaultBucket, 'finalize') ); @@ -293,10 +237,6 @@ describe('Storage Functions', () => { ); const result = subjectQualified.onFinalize(() => null); - expect(result.__trigger).to.deep.equal( - expectedTrigger('bucky', 'finalize') - ); - expect(result.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'finalize') ); @@ -308,8 +248,6 @@ describe('Storage Functions', () => { .object() .onFinalize(() => null); - expect(() => fn.__trigger).to.throw(Error); - expect(() => fn.__endpoint).to.throw(Error); }); @@ -349,10 +287,6 @@ describe('Storage Functions', () => { .object() .onMetadataUpdate(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger('bucky', 'metadataUpdate') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'metadataUpdate') ); @@ -361,10 +295,6 @@ describe('Storage Functions', () => { it('should use the default bucket when none is provided', () => { const cloudFunction = storage.object().onMetadataUpdate(() => null); - expect(cloudFunction.__trigger).to.deep.equal( - expectedTrigger(defaultBucket, 'metadataUpdate') - ); - expect(cloudFunction.__endpoint).to.deep.equal( expectedEndpoint(defaultBucket, 'metadataUpdate') ); @@ -377,10 +307,6 @@ describe('Storage Functions', () => { ); const result = subjectQualified.onMetadataUpdate(() => null); - expect(result.__trigger).to.deep.equal( - expectedTrigger('bucky', 'metadataUpdate') - ); - expect(result.__endpoint).to.deep.equal( expectedEndpoint('bucky', 'metadataUpdate') ); @@ -392,7 +318,6 @@ describe('Storage Functions', () => { .object() .onMetadataUpdate(() => null); - expect(() => fn.__trigger).to.throw(Error); expect(() => fn.__endpoint).to.throw(Error); }); @@ -443,7 +368,6 @@ describe('Storage Functions', () => { () => null ); - expect(cloudFunction.__trigger).to.deep.equal({}); expect(cloudFunction.__endpoint).to.be.undefined; }); @@ -484,7 +408,6 @@ describe('Storage Functions', () => { () => null ); - expect(cloudFunction.__trigger).to.deep.equal({}); expect(cloudFunction.__endpoint).to.be.undefined; }); @@ -525,7 +448,6 @@ describe('Storage Functions', () => { () => null ); - expect(cloudFunction.__trigger).to.deep.equal({}); expect(cloudFunction.__endpoint).to.be.undefined; }); @@ -566,7 +488,6 @@ describe('Storage Functions', () => { () => null ); - expect(cloudFunction.__trigger).to.deep.equal({}); expect(cloudFunction.__endpoint).to.be.undefined; }); @@ -608,16 +529,10 @@ describe('Storage Functions', () => { delete process.env.FIREBASE_CONFIG; }); - it('should not throw if __trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => storage.object().onArchive(() => null)).to.not.throw(Error); }); - it('should throw when trigger is accessed', () => { - expect(() => storage.object().onArchive(() => null).__trigger).to.throw( - Error - ); - }); - it('should throw when endpoint is accessed', () => { expect(() => storage.object().onArchive(() => null).__endpoint).to.throw( Error diff --git a/spec/v1/providers/tasks.spec.ts b/spec/v1/providers/tasks.spec.ts index 714f809fc..6382e00a4 100644 --- a/spec/v1/providers/tasks.spec.ts +++ b/spec/v1/providers/tasks.spec.ts @@ -44,23 +44,6 @@ describe('#onDispatch', () => { invoker: 'private', }).onDispatch(() => {}); - expect(result.__trigger).to.deep.equal({ - taskQueueTrigger: { - rateLimits: { - maxConcurrentDispatches: 30, - maxDispatchesPerSecond: 40, - }, - retryConfig: { - maxAttempts: 5, - maxRetrySeconds: 10, - maxBackoffSeconds: 20, - maxDoublings: 3, - minBackoffSeconds: 5, - }, - invoker: ['private'], - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv1', taskQueueTrigger: { @@ -90,17 +73,6 @@ describe('#onDispatch', () => { .tasks.taskQueue({ retryConfig: { maxAttempts: 5 } }) .onDispatch(() => null); - expect(fn.__trigger).to.deep.equal({ - regions: ['us-east1'], - availableMemoryMb: 256, - timeout: '90s', - taskQueueTrigger: { - retryConfig: { - maxAttempts: 5, - }, - }, - }); - expect(fn.__endpoint).to.deep.equal({ platform: 'gcfv1', region: ['us-east1'], @@ -160,7 +132,6 @@ describe('#onDispatch', () => { describe('handler namespace', () => { it('should return an empty trigger', () => { const result = functions.handler.tasks.taskQueue.onDispatch(() => null); - expect(result.__trigger).to.deep.equal({}); expect(result.__endpoint).to.be.undefined; }); }); diff --git a/spec/v1/providers/testLab.spec.ts b/spec/v1/providers/testLab.spec.ts index 8836d1704..be2922e4e 100644 --- a/spec/v1/providers/testLab.spec.ts +++ b/spec/v1/providers/testLab.spec.ts @@ -38,14 +38,6 @@ describe('Test Lab Functions', () => { it('should return a trigger/endpoint with appropriate values', () => { const func = testLab.testMatrix().onComplete(() => null); - expect(func.__trigger).to.deep.equal({ - eventTrigger: { - service: 'testing.googleapis.com', - eventType: 'google.testing.testMatrix.complete', - resource: 'projects/project1/testMatrices/{matrix}', - }, - }); - expect(func.__endpoint).to.deep.equal({ platform: 'gcfv1', eventTrigger: { @@ -157,18 +149,12 @@ describe('Test Lab Functions', () => { }); describe('process.env.GCLOUD_PROJECT not set', () => { - it('should not throw if trigger is not accessed', () => { + it('should not throw if __endpoint is not accessed', () => { expect(() => testLab.testMatrix().onComplete(() => null)).to.not.throw( Error ); }); - it('should throw when trigger is accessed', () => { - expect( - () => testLab.testMatrix().onComplete(() => null).__trigger - ).to.throw(Error); - }); - it('should throw when endpoint is accessed', () => { expect( () => testLab.testMatrix().onComplete(() => null).__endpoint diff --git a/spec/v2/providers/fixtures.ts b/spec/v2/providers/fixtures.ts index f330efed1..84ab2344c 100644 --- a/spec/v2/providers/fixtures.ts +++ b/spec/v2/providers/fixtures.ts @@ -1,5 +1,4 @@ import { ManifestEndpoint } from '../../../src/runtime/manifest'; -import { TriggerAnnotation } from '../../../src/v2/core'; import * as options from '../../../src/v2/options'; export const FULL_OPTIONS: options.GlobalOptions = { @@ -20,24 +19,6 @@ export const FULL_OPTIONS: options.GlobalOptions = { secrets: ['MY_SECRET'], }; -export const FULL_TRIGGER: TriggerAnnotation = { - platform: 'gcfv2', - regions: ['us-west1'], - availableMemoryMb: 512, - timeout: '60s', - minInstances: 1, - maxInstances: 3, - concurrency: 20, - vpcConnector: 'aConnector', - vpcConnectorEgressSettings: 'ALL_TRAFFIC', - serviceAccountEmail: 'root@aProject.iam.gserviceaccount.com', - ingressSettings: 'ALLOW_ALL', - labels: { - hello: 'world', - }, - secrets: ['MY_SECRET'], -}; - export const FULL_ENDPOINT: ManifestEndpoint = { platform: 'gcfv2', region: ['us-west1'], diff --git a/spec/v2/providers/https.spec.ts b/spec/v2/providers/https.spec.ts index 65e573849..882c7e854 100644 --- a/spec/v2/providers/https.spec.ts +++ b/spec/v2/providers/https.spec.ts @@ -31,7 +31,7 @@ import { MockRequest, } from '../../fixtures/mockrequest'; import { runHandler } from '../../helper'; -import { FULL_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from './fixtures'; +import { FULL_ENDPOINT, FULL_OPTIONS } from './fixtures'; describe('onRequest', () => { beforeEach(() => { @@ -48,14 +48,6 @@ describe('onRequest', () => { res.send(200); }); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - httpsTrigger: { - allowInsecure: false, - }, - labels: {}, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', httpsTrigger: {}, @@ -75,15 +67,6 @@ describe('onRequest', () => { } ); - expect(result.__trigger).to.deep.equal({ - ...FULL_TRIGGER, - httpsTrigger: { - allowInsecure: false, - invoker: ['service-account1@', 'service-account2@'], - }, - regions: ['us-west1', 'us-central1'], - }); - expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, httpsTrigger: { @@ -112,18 +95,6 @@ describe('onRequest', () => { } ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - httpsTrigger: { - allowInsecure: false, - invoker: ['private'], - }, - concurrency: 20, - minInstances: 3, - regions: ['us-west1', 'us-central1'], - labels: {}, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', httpsTrigger: { @@ -233,16 +204,6 @@ describe('onCall', () => { it('should return a minimal trigger/endpoint with appropriate values', () => { const result = https.onCall((request) => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - httpsTrigger: { - allowInsecure: false, - }, - labels: { - 'deployment-callable': 'true', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', callableTrigger: {}, @@ -253,17 +214,6 @@ describe('onCall', () => { it('should create a complex trigger/endpoint with appropriate values', () => { const result = https.onCall(FULL_OPTIONS, (request) => 42); - expect(result.__trigger).to.deep.equal({ - ...FULL_TRIGGER, - httpsTrigger: { - allowInsecure: false, - }, - labels: { - ...FULL_TRIGGER.labels, - 'deployment-callable': 'true', - }, - }); - expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, callableTrigger: {}, @@ -285,19 +235,6 @@ describe('onCall', () => { (request) => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - httpsTrigger: { - allowInsecure: false, - }, - concurrency: 20, - minInstances: 3, - regions: ['us-west1', 'us-central1'], - labels: { - 'deployment-callable': 'true', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', callableTrigger: {}, diff --git a/spec/v2/providers/pubsub.spec.ts b/spec/v2/providers/pubsub.spec.ts index 395dadace..ec4dddbae 100644 --- a/spec/v2/providers/pubsub.spec.ts +++ b/spec/v2/providers/pubsub.spec.ts @@ -3,7 +3,7 @@ import { expect } from 'chai'; import { CloudEvent } from '../../../src/v2/core'; import * as options from '../../../src/v2/options'; import * as pubsub from '../../../src/v2/providers/pubsub'; -import { FULL_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from './fixtures'; +import { FULL_ENDPOINT, FULL_OPTIONS } from './fixtures'; const EVENT_TRIGGER = { eventType: 'google.cloud.pubsub.topic.v1.messagePublished', @@ -31,12 +31,6 @@ describe('onMessagePublished', () => { it('should return a minimal trigger/endpoint with appropriate values', () => { const result = pubsub.onMessagePublished('topic', () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - eventTrigger: EVENT_TRIGGER, - labels: {}, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', eventTrigger: ENDPOINT_EVENT_TRIGGER, @@ -50,11 +44,6 @@ describe('onMessagePublished', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - ...FULL_TRIGGER, - eventTrigger: EVENT_TRIGGER, - }); - expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, eventTrigger: ENDPOINT_EVENT_TRIGGER, @@ -77,15 +66,6 @@ describe('onMessagePublished', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - concurrency: 20, - minInstances: 3, - regions: ['us-west1'], - labels: {}, - eventTrigger: EVENT_TRIGGER, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', concurrency: 20, @@ -107,15 +87,6 @@ describe('onMessagePublished', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - minInstances: 3, - regions: ['us-west1'], - labels: {}, - eventTrigger: EVENT_TRIGGER, - failurePolicy: { retry: true }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', minInstances: 3, diff --git a/spec/v2/providers/storage.spec.ts b/spec/v2/providers/storage.spec.ts index f70544c07..4122380b5 100644 --- a/spec/v2/providers/storage.spec.ts +++ b/spec/v2/providers/storage.spec.ts @@ -2,12 +2,7 @@ import { expect } from 'chai'; import * as config from '../../../src/common/config'; import * as options from '../../../src/v2/options'; import * as storage from '../../../src/v2/providers/storage'; -import { FULL_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from './fixtures'; - -const EVENT_TRIGGER = { - eventType: 'event-type', - resource: 'some-bucket', -}; +import { FULL_ENDPOINT, FULL_OPTIONS } from './fixtures'; const ENDPOINT_EVENT_TRIGGER = { eventType: 'event-type', @@ -79,12 +74,6 @@ describe('v2/storage', () => { it('should create a minimal trigger/endpoint with bucket', () => { const result = storage.onOperation('event-type', 'some-bucket', () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: EVENT_TRIGGER, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -101,16 +90,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...EVENT_TRIGGER, - resource: 'default-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -129,12 +108,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: EVENT_TRIGGER, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -152,11 +125,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - ...FULL_TRIGGER, - eventTrigger: EVENT_TRIGGER, - }); - expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, eventTrigger: ENDPOINT_EVENT_TRIGGER, @@ -180,15 +148,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - concurrency: 20, - minInstances: 3, - regions: ['us-west1'], - labels: {}, - eventTrigger: EVENT_TRIGGER, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', concurrency: 20, @@ -201,10 +160,6 @@ describe('v2/storage', () => { }); describe('onObjectArchived', () => { - const ARCHIVED_TRIGGER = { - ...EVENT_TRIGGER, - eventType: storage.archivedEvent, - }; const ENDPOINT_ARCHIVED_TRIGGER = { ...ENDPOINT_EVENT_TRIGGER, eventType: storage.archivedEvent, @@ -219,15 +174,6 @@ describe('v2/storage', () => { const result = storage.onObjectArchived(() => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...ARCHIVED_TRIGGER, - resource: 'default-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -241,15 +187,6 @@ describe('v2/storage', () => { it('should accept bucket and handler', () => { const result = storage.onObjectArchived('my-bucket', () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...ARCHIVED_TRIGGER, - resource: 'my-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -266,16 +203,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...ARCHIVED_TRIGGER, - resource: 'my-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -292,16 +219,6 @@ describe('v2/storage', () => { const result = storage.onObjectArchived({ region: 'us-west1' }, () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...ARCHIVED_TRIGGER, - resource: 'default-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -315,10 +232,6 @@ describe('v2/storage', () => { }); describe('onObjectFinalized', () => { - const FINALIZED_TRIGGER = { - ...EVENT_TRIGGER, - eventType: storage.finalizedEvent, - }; const ENDPOINT_FINALIZED_TRIGGER = { ...ENDPOINT_EVENT_TRIGGER, eventType: storage.finalizedEvent, @@ -333,15 +246,6 @@ describe('v2/storage', () => { const result = storage.onObjectFinalized(() => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...FINALIZED_TRIGGER, - resource: 'default-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -355,15 +259,6 @@ describe('v2/storage', () => { it('should accept bucket and handler', () => { const result = storage.onObjectFinalized('my-bucket', () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...FINALIZED_TRIGGER, - resource: 'my-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -380,16 +275,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...FINALIZED_TRIGGER, - resource: 'my-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -409,16 +294,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...FINALIZED_TRIGGER, - resource: 'default-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -432,10 +307,6 @@ describe('v2/storage', () => { }); describe('onObjectDeleted', () => { - const DELETED_TRIGGER = { - ...EVENT_TRIGGER, - eventType: storage.deletedEvent, - }; const ENDPOINT_DELETED_TRIGGER = { ...ENDPOINT_EVENT_TRIGGER, eventType: storage.deletedEvent, @@ -450,15 +321,6 @@ describe('v2/storage', () => { const result = storage.onObjectDeleted(() => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...DELETED_TRIGGER, - resource: 'default-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -472,15 +334,6 @@ describe('v2/storage', () => { it('should accept bucket and handler', () => { const result = storage.onObjectDeleted('my-bucket', () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...DELETED_TRIGGER, - resource: 'my-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -497,16 +350,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...DELETED_TRIGGER, - resource: 'my-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -523,16 +366,6 @@ describe('v2/storage', () => { const result = storage.onObjectDeleted({ region: 'us-west1' }, () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...DELETED_TRIGGER, - resource: 'default-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -546,10 +379,6 @@ describe('v2/storage', () => { }); describe('onObjectMetadataUpdated', () => { - const METADATA_TRIGGER = { - ...EVENT_TRIGGER, - eventType: storage.metadataUpdatedEvent, - }; const ENDPOINT_METADATA_TRIGGER = { ...ENDPOINT_EVENT_TRIGGER, eventType: storage.metadataUpdatedEvent, @@ -564,15 +393,6 @@ describe('v2/storage', () => { const result = storage.onObjectMetadataUpdated(() => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...METADATA_TRIGGER, - resource: 'default-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -586,15 +406,6 @@ describe('v2/storage', () => { it('should accept bucket and handler', () => { const result = storage.onObjectMetadataUpdated('my-bucket', () => 42); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...METADATA_TRIGGER, - resource: 'my-bucket', - }, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -611,16 +422,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...METADATA_TRIGGER, - resource: 'my-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, @@ -640,16 +441,6 @@ describe('v2/storage', () => { () => 42 ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - labels: {}, - eventTrigger: { - ...METADATA_TRIGGER, - resource: 'default-bucket', - }, - regions: ['us-west1'], - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', labels: {}, diff --git a/spec/v2/providers/tasks.spec.ts b/spec/v2/providers/tasks.spec.ts index f0f8c9cc5..cf4ffd019 100644 --- a/spec/v2/providers/tasks.spec.ts +++ b/spec/v2/providers/tasks.spec.ts @@ -26,7 +26,7 @@ import * as options from '../../../src/v2/options'; import { onTaskDispatched, Request } from '../../../src/v2/providers/tasks'; import { MockRequest } from '../../fixtures/mockrequest'; import { runHandler } from '../../helper'; -import { FULL_ENDPOINT, FULL_OPTIONS, FULL_TRIGGER } from './fixtures'; +import { FULL_ENDPOINT, FULL_OPTIONS } from './fixtures'; describe('onTaskDispatched', () => { beforeEach(() => { @@ -41,12 +41,6 @@ describe('onTaskDispatched', () => { it('should return a minimal trigger/endpoint with appropriate values', () => { const result = onTaskDispatched(() => {}); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - taskQueueTrigger: {}, - labels: {}, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', taskQueueTrigger: {}, @@ -74,24 +68,6 @@ describe('onTaskDispatched', () => { () => {} ); - expect(result.__trigger).to.deep.equal({ - ...FULL_TRIGGER, - taskQueueTrigger: { - retryConfig: { - maxAttempts: 4, - maxRetrySeconds: 10, - maxDoublings: 3, - minBackoffSeconds: 1, - maxBackoffSeconds: 2, - }, - rateLimits: { - maxConcurrentDispatches: 5, - maxDispatchesPerSecond: 10, - }, - invoker: ['private'], - }, - }); - expect(result.__endpoint).to.deep.equal({ ...FULL_ENDPOINT, platform: 'gcfv2', @@ -127,15 +103,6 @@ describe('onTaskDispatched', () => { (request) => {} ); - expect(result.__trigger).to.deep.equal({ - platform: 'gcfv2', - taskQueueTrigger: {}, - concurrency: 20, - minInstances: 3, - regions: ['us-west1'], - labels: {}, - }); - expect(result.__endpoint).to.deep.equal({ platform: 'gcfv2', taskQueueTrigger: {}, diff --git a/src/common/encoding.ts b/src/common/encoding.ts index 554c5fcb1..0e5724df3 100644 --- a/src/common/encoding.ts +++ b/src/common/encoding.ts @@ -22,17 +22,6 @@ // Copied from firebase-tools/src/gcp/proto -/** - * A type alias used to annotate interfaces as using a google.protobuf.Duration. - * This type is parsed/encoded as a string of seconds + the "s" prefix. - */ -export type Duration = string; - -/** Get a google.protobuf.Duration for a number of seconds. */ -export function durationFromSeconds(s: number): Duration { - return `${s}s`; -} - /** * Utility function to help copy fields from type A to B. * As a safety net, catches typos or fields that aren't named the same @@ -72,27 +61,6 @@ export function convertIfPresent( dest[destField] = converter(src[srcField]); } -export function serviceAccountFromShorthand( - serviceAccount: string -): string | null { - if (serviceAccount === 'default') { - return null; - } else if (serviceAccount.endsWith('@')) { - if (!process.env.GCLOUD_PROJECT) { - throw new Error( - `Unable to determine email for service account '${serviceAccount}' because process.env.GCLOUD_PROJECT is not set.` - ); - } - return `${serviceAccount}${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`; - } else if (serviceAccount.includes('@')) { - return serviceAccount; - } else { - throw new Error( - `Invalid option for serviceAccount: '${serviceAccount}'. Valid options are 'default', a service account email, or '{serviceAccountName}@'` - ); - } -} - export function convertInvoker(invoker: string | string[]): string[] { if (typeof invoker === 'string') { invoker = [invoker]; diff --git a/src/v1/cloud-functions.ts b/src/v1/cloud-functions.ts index 64c6bccb1..d73ed604f 100644 --- a/src/v1/cloud-functions.ts +++ b/src/v1/cloud-functions.ts @@ -23,20 +23,9 @@ import { Request, Response } from 'express'; import * as _ from 'lodash'; import { warn } from '../logger'; -import { - DEFAULT_FAILURE_POLICY, - DeploymentOptions, - FailurePolicy, - Schedule, -} from './function-configuration'; +import { DeploymentOptions } from './function-configuration'; export { Request, Response }; -import { - convertIfPresent, - copyIfPresent, - Duration, - durationFromSeconds, - serviceAccountFromShorthand, -} from '../common/encoding'; +import { convertIfPresent, copyIfPresent } from '../common/encoding'; import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest'; /** @hidden */ @@ -256,36 +245,6 @@ export interface Resource { labels?: { [tag: string]: string }; } -/** - * TriggerAnnotion is used internally by the firebase CLI to understand what - * type of Cloud Function to deploy. - */ -interface TriggerAnnotation { - availableMemoryMb?: number; - blockingTrigger?: { - eventType: string; - options?: Record; - }; - eventTrigger?: { - eventType: string; - resource: string; - service: string; - }; - failurePolicy?: FailurePolicy; - httpsTrigger?: { - invoker?: string[]; - }; - labels?: { [key: string]: string }; - regions?: string[]; - schedule?: Schedule; - timeout?: Duration; - vpcConnector?: string; - vpcConnectorEgressSettings?: string; - serviceAccountEmail?: string; - ingressSettings?: string; - secrets?: string[]; -} - /** * A Runnable has a `run` method which directly invokes the user-defined * function - useful for unit testing. @@ -306,9 +265,6 @@ export interface Runnable { export interface HttpsFunction { (req: Request, resp: Response): void | Promise; - /** @alpha */ - __trigger: TriggerAnnotation; - /** @alpha */ __endpoint: ManifestEndpoint; @@ -322,9 +278,6 @@ export interface HttpsFunction { export interface BlockingFunction { (req: Request, resp: Response): void | Promise; - /** @alpha */ - __trigger: TriggerAnnotation; - /** @alpha */ __endpoint: ManifestEndpoint; @@ -342,9 +295,6 @@ export interface BlockingFunction { export interface CloudFunction extends Runnable { (input: any, context?: any): PromiseLike | any; - /** @alpha */ - __trigger: TriggerAnnotation; - /** @alpha */ __endpoint: ManifestEndpoint; @@ -450,26 +400,6 @@ export function makeCloudFunction({ }); }; - Object.defineProperty(cloudFunction, '__trigger', { - get: () => { - if (triggerResource() == null) { - return {}; - } - - const trigger: any = _.assign(optionsToTrigger(options), { - eventTrigger: { - resource: triggerResource(), - eventType: legacyEventType || provider + '.' + eventType, - service, - }, - }); - if (!_.isEmpty(labels)) { - trigger.labels = { ...trigger.labels, ...labels }; - } - return trigger; - }, - }); - Object.defineProperty(cloudFunction, '__endpoint', { get: () => { if (triggerResource() == null) { @@ -565,67 +495,6 @@ function _detectAuthType(event: Event) { return 'UNAUTHENTICATED'; } -/** @hidden */ -export function optionsToTrigger(options: DeploymentOptions) { - const trigger: any = {}; - copyIfPresent( - trigger, - options, - 'regions', - 'schedule', - 'minInstances', - 'maxInstances', - 'ingressSettings', - 'vpcConnectorEgressSettings', - 'vpcConnector', - 'labels', - 'secrets' - ); - convertIfPresent( - trigger, - options, - 'failurePolicy', - 'failurePolicy', - (policy) => { - if (policy === false) { - return undefined; - } else if (policy === true) { - return DEFAULT_FAILURE_POLICY; - } else { - return policy; - } - } - ); - convertIfPresent( - trigger, - options, - 'timeout', - 'timeoutSeconds', - durationFromSeconds - ); - convertIfPresent(trigger, options, 'availableMemoryMb', 'memory', (mem) => { - const memoryLookup = { - '128MB': 128, - '256MB': 256, - '512MB': 512, - '1GB': 1024, - '2GB': 2048, - '4GB': 4096, - '8GB': 8192, - }; - return memoryLookup[mem]; - }); - convertIfPresent( - trigger, - options, - 'serviceAccountEmail', - 'serviceAccount', - serviceAccountFromShorthand - ); - - return trigger; -} - export function optionsToEndpoint( options: DeploymentOptions ): ManifestEndpoint { diff --git a/src/v1/function-configuration.ts b/src/v1/function-configuration.ts index 73cc64eac..6236ce976 100644 --- a/src/v1/function-configuration.ts +++ b/src/v1/function-configuration.ts @@ -92,10 +92,6 @@ export interface FailurePolicy { retry: {}; } -export const DEFAULT_FAILURE_POLICY: FailurePolicy = { - retry: {}, -}; - export const MAX_NUMBER_USER_LABELS = 58; export interface RuntimeOptions { diff --git a/src/v1/handler-builder.ts b/src/v1/handler-builder.ts index 7b2831e7c..9a7e11f62 100644 --- a/src/v1/handler-builder.ts +++ b/src/v1/handler-builder.ts @@ -70,7 +70,6 @@ export class HandlerBuilder { handler: (req: express.Request, resp: express.Response) => void ): HttpsFunction => { const func = https._onRequestWithOptions(handler, {}); - func.__trigger = {}; func.__endpoint = undefined; func.__requiredAPIs = undefined; return func; @@ -82,7 +81,6 @@ export class HandlerBuilder { ) => any | Promise ): HttpsFunction => { const func = https._onCallWithOptions(handler, {}); - func.__trigger = {}; func.__endpoint = undefined; func.__requiredAPIs = undefined; return func; @@ -111,7 +109,6 @@ export class HandlerBuilder { ): HttpsFunction => { const builder = new tasks.TaskQueueBuilder(); const func = builder.onDispatch(handler); - func.__trigger = {}; func.__endpoint = undefined; func.__requiredAPIs = undefined; return func; diff --git a/src/v1/providers/auth.ts b/src/v1/providers/auth.ts index 2f6a66a3a..190441c55 100644 --- a/src/v1/providers/auth.ts +++ b/src/v1/providers/auth.ts @@ -40,7 +40,6 @@ import { EventContext, makeCloudFunction, optionsToEndpoint, - optionsToTrigger, } from '../cloud-functions'; import { DeploymentOptions } from '../function-configuration'; @@ -208,19 +207,6 @@ export class UserBuilder { const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`; - func.__trigger = { - labels: {}, - ...optionsToTrigger(this.options), - blockingTrigger: { - eventType: legacyEventType, - options: { - accessToken, - idToken, - refreshToken, - }, - }, - }; - func.__endpoint = { platform: 'gcfv1', labels: {}, diff --git a/src/v1/providers/https.ts b/src/v1/providers/https.ts index db3cf092e..8a8c7aebd 100644 --- a/src/v1/providers/https.ts +++ b/src/v1/providers/https.ts @@ -30,12 +30,7 @@ import { onCallHandler, Request, } from '../../common/providers/https'; -import { - HttpsFunction, - optionsToEndpoint, - optionsToTrigger, - Runnable, -} from '../cloud-functions'; +import { HttpsFunction, optionsToEndpoint, Runnable } from '../cloud-functions'; import { DeploymentOptions } from '../function-configuration'; export { Request, CallableContext, FunctionsErrorCode, HttpsError }; @@ -66,21 +61,10 @@ export function _onRequestWithOptions( handler: (req: Request, resp: express.Response) => void | Promise, options: DeploymentOptions ): HttpsFunction { - // lets us add __trigger without altering handler: + // lets us add __endpoint without altering handler: const cloudFunction: any = (req: Request, res: express.Response) => { return handler(req, res); }; - cloudFunction.__trigger = { - ...optionsToTrigger(options), - httpsTrigger: {}, - }; - convertIfPresent( - cloudFunction.__trigger.httpsTrigger, - options, - 'invoker', - 'invoker', - convertInvoker - ); // TODO parse the options cloudFunction.__endpoint = { @@ -116,13 +100,6 @@ export function _onCallWithOptions( fixedLen ); - func.__trigger = { - labels: {}, - ...optionsToTrigger(options), - httpsTrigger: {}, - }; - func.__trigger.labels['deployment-callable'] = 'true'; - func.__endpoint = { platform: 'gcfv1', labels: {}, diff --git a/src/v1/providers/tasks.ts b/src/v1/providers/tasks.ts index dc26963a2..284c91262 100644 --- a/src/v1/providers/tasks.ts +++ b/src/v1/providers/tasks.ts @@ -35,7 +35,7 @@ import { TaskContext, } from '../../common/providers/tasks'; import { ManifestEndpoint, ManifestRequiredAPI } from '../../runtime/manifest'; -import { optionsToEndpoint, optionsToTrigger } from '../cloud-functions'; +import { optionsToEndpoint } from '../cloud-functions'; import { DeploymentOptions } from '../function-configuration'; export { RetryConfig, RateLimits, TaskContext }; @@ -64,9 +64,6 @@ export interface TaskQueueOptions { export interface TaskQueueFunction { (req: Request, res: express.Response): Promise; - /** @alpha */ - __trigger: unknown; - /** @alpha */ __endpoint: ManifestEndpoint; @@ -109,20 +106,6 @@ export class TaskQueueBuilder { handler(data, context); const func: any = onDispatchHandler(fixedLen); - func.__trigger = { - ...optionsToTrigger(this.depOpts || {}), - taskQueueTrigger: {}, - }; - copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig'); - copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits'); - convertIfPresent( - func.__trigger.taskQueueTrigger, - this.tqOpts, - 'invoker', - 'invoker', - convertInvoker - ); - func.__endpoint = { platform: 'gcfv1', ...optionsToEndpoint(this.depOpts), diff --git a/src/v2/core.ts b/src/v2/core.ts index 5e71d2458..023a488e8 100644 --- a/src/v2/core.ts +++ b/src/v2/core.ts @@ -27,37 +27,6 @@ import { ManifestEndpoint } from '../runtime/manifest'; -/** @internal */ -export interface TriggerAnnotation { - platform?: string; - concurrency?: number; - minInstances?: number; - maxInstances?: number; - availableMemoryMb?: number; - eventTrigger?: { - eventType: string; - resource: string; - service: string; - }; - failurePolicy?: { retry: boolean }; - httpsTrigger?: { - invoker?: string[]; - }; - labels?: { [key: string]: string }; - regions?: string[]; - timeout?: string; - vpcConnector?: string; - vpcConnectorEgressSettings?: string; - serviceAccountEmail?: string; - ingressSettings?: string; - secrets?: string[]; - blockingTrigger?: { - eventType: string; - options?: Record; - }; - // TODO: schedule -} - /** * A CloudEventBase is the base of a cross-platform format for encoding a serverless event. * More information can be found in https://github.com/cloudevents/spec @@ -96,8 +65,6 @@ export interface CloudEvent { export interface CloudFunction> { (raw: CloudEvent): any | Promise; - /** @alpha */ - __trigger?: unknown; /** @alpha */ __endpoint: ManifestEndpoint; diff --git a/src/v2/options.ts b/src/v2/options.ts index c2ebf5248..bb7b27fd9 100644 --- a/src/v2/options.ts +++ b/src/v2/options.ts @@ -25,15 +25,9 @@ * @packageDocumentation */ -import { - convertIfPresent, - copyIfPresent, - durationFromSeconds, - serviceAccountFromShorthand, -} from '../common/encoding'; +import { convertIfPresent, copyIfPresent } from '../common/encoding'; import * as logger from '../logger'; import { ManifestEndpoint } from '../runtime/manifest'; -import { TriggerAnnotation } from './core'; import { declaredParams } from './params'; import { ParamSpec } from './params/types'; import { HttpsOptions } from './providers/https'; @@ -221,68 +215,6 @@ export interface EventHandlerOptions extends GlobalOptions { retry?: boolean; } -/** - * Apply GlobalOptions to trigger definitions. - * @internal - */ -export function optionsToTriggerAnnotations( - opts: GlobalOptions | EventHandlerOptions | HttpsOptions -): TriggerAnnotation { - const annotation: TriggerAnnotation = {}; - copyIfPresent( - annotation, - opts, - 'concurrency', - 'minInstances', - 'maxInstances', - 'ingressSettings', - 'labels', - 'vpcConnector', - 'vpcConnectorEgressSettings', - 'secrets' - ); - convertIfPresent( - annotation, - opts, - 'availableMemoryMb', - 'memory', - (mem: MemoryOption) => { - return MemoryOptionToMB[mem]; - } - ); - convertIfPresent(annotation, opts, 'regions', 'region', (region) => { - if (typeof region === 'string') { - return [region]; - } - return region; - }); - convertIfPresent( - annotation, - opts, - 'serviceAccountEmail', - 'serviceAccount', - serviceAccountFromShorthand - ); - convertIfPresent( - annotation, - opts, - 'timeout', - 'timeoutSeconds', - durationFromSeconds - ); - convertIfPresent( - annotation, - (opts as any) as EventHandlerOptions, - 'failurePolicy', - 'retry', - (retry: boolean) => { - return retry ? { retry: true } : null; - } - ); - - return annotation; -} - /** * Apply GlobalOptions to endpoint manifest. * @internal diff --git a/src/v2/providers/https.ts b/src/v2/providers/https.ts index dad7355cd..7490eb2a2 100644 --- a/src/v2/providers/https.ts +++ b/src/v2/providers/https.ts @@ -159,8 +159,6 @@ export type HttpsFunction = (( /** An Express response object, for this function to respond to callers. */ res: express.Response ) => void | Promise) & { - /** @alpha */ - __trigger?: unknown; /** @alpha */ __endpoint: ManifestEndpoint; }; @@ -232,39 +230,6 @@ export function onRequest( }; } - Object.defineProperty(handler, '__trigger', { - get: () => { - const baseOpts = options.optionsToTriggerAnnotations( - options.getGlobalOptions() - ); - // global options calls region a scalar and https allows it to be an array, - // but optionsToTriggerAnnotations handles both cases. - const specificOpts = options.optionsToTriggerAnnotations( - opts as options.GlobalOptions - ); - const trigger: any = { - platform: 'gcfv2', - ...baseOpts, - ...specificOpts, - labels: { - ...baseOpts?.labels, - ...specificOpts?.labels, - }, - httpsTrigger: { - allowInsecure: false, - }, - }; - convertIfPresent( - trigger.httpsTrigger, - opts, - 'invoker', - 'invoker', - convertInvoker - ); - return trigger; - }, - }); - const baseOpts = options.optionsToEndpoint(options.getGlobalOptions()); // global options calls region a scalar and https allows it to be an array, // but optionsToTriggerAnnotations handles both cases. @@ -335,30 +300,6 @@ export function onCall>( fixedLen ); - Object.defineProperty(func, '__trigger', { - get: () => { - const baseOpts = options.optionsToTriggerAnnotations( - options.getGlobalOptions() - ); - // global options calls region a scalar and https allows it to be an array, - // but optionsToTriggerAnnotations handles both cases. - const specificOpts = options.optionsToTriggerAnnotations(opts); - return { - platform: 'gcfv2', - ...baseOpts, - ...specificOpts, - labels: { - ...baseOpts?.labels, - ...specificOpts?.labels, - 'deployment-callable': 'true', - }, - httpsTrigger: { - allowInsecure: false, - }, - }; - }, - }); - const baseOpts = options.optionsToEndpoint(options.getGlobalOptions()); // global options calls region a scalar and https allows it to be an array, // but optionsToEndpoint handles both cases. diff --git a/src/v2/providers/pubsub.ts b/src/v2/providers/pubsub.ts index 380ed6946..7b7993bc5 100644 --- a/src/v2/providers/pubsub.ts +++ b/src/v2/providers/pubsub.ts @@ -303,29 +303,6 @@ export function onMessagePublished( func.run = handler; - Object.defineProperty(func, '__trigger', { - get: () => { - const baseOpts = options.optionsToTriggerAnnotations( - options.getGlobalOptions() - ); - const specificOpts = options.optionsToTriggerAnnotations(opts); - - return { - platform: 'gcfv2', - ...baseOpts, - ...specificOpts, - labels: { - ...baseOpts?.labels, - ...specificOpts?.labels, - }, - eventTrigger: { - eventType: 'google.cloud.pubsub.topic.v1.messagePublished', - resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`, - }, - }; - }, - }); - const baseOpts = options.optionsToEndpoint(options.getGlobalOptions()); const specificOpts = options.optionsToEndpoint(opts); diff --git a/src/v2/providers/storage.ts b/src/v2/providers/storage.ts index e9771758a..0087119e0 100644 --- a/src/v2/providers/storage.ts +++ b/src/v2/providers/storage.ts @@ -569,29 +569,6 @@ export function onOperation( func.run = handler; - Object.defineProperty(func, '__trigger', { - get: () => { - const baseOpts = options.optionsToTriggerAnnotations( - options.getGlobalOptions() - ); - const specificOpts = options.optionsToTriggerAnnotations(opts); - - return { - platform: 'gcfv2', - ...baseOpts, - ...specificOpts, - labels: { - ...baseOpts?.labels, - ...specificOpts?.labels, - }, - eventTrigger: { - eventType, - resource: bucket, // TODO(colerogers): replace with 'bucket,' eventually - }, - }; - }, - }); - // TypeScript doesn't recognize defineProperty as adding a property and complains // that __endpoint doesn't exist. We can either cast to any and lose all type safety // or we can just assign a meaningless value before calling defineProperty. diff --git a/src/v2/providers/tasks.ts b/src/v2/providers/tasks.ts index df3b9b8c2..eae3e53dd 100644 --- a/src/v2/providers/tasks.ts +++ b/src/v2/providers/tasks.ts @@ -206,38 +206,6 @@ export function onTaskDispatched( const fixedLen = (req: Request) => handler(req); const func: any = onDispatchHandler(fixedLen); - Object.defineProperty(func, '__trigger', { - get: () => { - const baseOpts = options.optionsToTriggerAnnotations( - options.getGlobalOptions() - ); - // global options calls region a scalar and https allows it to be an array, - // but optionsToTriggerAnnotations handles both cases. - const specificOpts = options.optionsToTriggerAnnotations( - opts as options.GlobalOptions - ); - const taskQueueTrigger: Record = {}; - copyIfPresent(taskQueueTrigger, opts, 'retryConfig', 'rateLimits'); - convertIfPresent( - taskQueueTrigger, - opts, - 'invoker', - 'invoker', - convertInvoker - ); - return { - platform: 'gcfv2', - ...baseOpts, - ...specificOpts, - labels: { - ...baseOpts?.labels, - ...specificOpts?.labels, - }, - taskQueueTrigger, - }; - }, - }); - const baseOpts = options.optionsToEndpoint(options.getGlobalOptions()); // global options calls region a scalar and https allows it to be an array, // but optionsToManifestEndpoint handles both cases.