Skip to content

Commit 11d35b3

Browse files
refactor!: rename cloudevent to CloudEvent (#379)
This commit is a refactor of all our cloudevent identifiers to be more consistent. Depending on the context we will always prefer: `CloudEvent`, `cloudEvent`, or `cloud_event`. We will avoid `cloudevent` Fixes #378
1 parent 292ade9 commit 11d35b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+78
-78
lines changed

docs/generated/api.d.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ import * as express from 'express';
55
/**
66
* Register a function that handles CloudEvents.
77
* @param functionName - the name of the function
8-
* @param handler - the function to trigger when handling cloudevents
8+
* @param handler - the function to trigger when handling CloudEvents
99
* @public
1010
*/
11-
export declare const cloudevent: (functionName: string, handler: CloudEventFunction) => void;
11+
export declare const cloudEvent: (functionName: string, handler: CloudEventFunction) => void;
1212

1313
/**
14-
* A cloudevent function handler.
14+
* A CloudEvent function handler.
1515
* @public
1616
*/
1717
export declare interface CloudEventFunction {
18-
(cloudevent: CloudEventsContext): any;
18+
(cloudEvent: CloudEventsContext): any;
1919
}
2020

2121
/**
22-
* A cloudevent function handler with callback.
22+
* A CloudEvent function handler with callback.
2323
* @public
2424
*/
2525
export declare interface CloudEventFunctionWithCallback {
26-
(cloudevent: CloudEventsContext, callback: Function): any;
26+
(cloudEvent: CloudEventsContext, callback: Function): any;
2727
}
2828

2929
/**

docs/generated/api.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@
171171
"members": [
172172
{
173173
"kind": "Variable",
174-
"canonicalReference": "@google-cloud/functions-framework!cloudevent:var",
175-
"docComment": "/**\n * Register a function that handles CloudEvents.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to trigger when handling cloudevents\n *\n * @public\n */\n",
174+
"canonicalReference": "@google-cloud/functions-framework!cloudEvent:var",
175+
"docComment": "/**\n * Register a function that handles CloudEvents.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to trigger when handling CloudEvents\n *\n * @public\n */\n",
176176
"excerptTokens": [
177177
{
178178
"kind": "Content",
179-
"text": "cloudevent: "
179+
"text": "cloudEvent: "
180180
},
181181
{
182182
"kind": "Content",
@@ -193,7 +193,7 @@
193193
}
194194
],
195195
"releaseTag": "Public",
196-
"name": "cloudevent",
196+
"name": "cloudEvent",
197197
"variableTypeTokenRange": {
198198
"startIndex": 1,
199199
"endIndex": 4
@@ -202,7 +202,7 @@
202202
{
203203
"kind": "Interface",
204204
"canonicalReference": "@google-cloud/functions-framework!CloudEventFunction:interface",
205-
"docComment": "/**\n * A cloudevent function handler.\n *\n * @public\n */\n",
205+
"docComment": "/**\n * A CloudEvent function handler.\n *\n * @public\n */\n",
206206
"excerptTokens": [
207207
{
208208
"kind": "Content",
@@ -219,7 +219,7 @@
219219
"excerptTokens": [
220220
{
221221
"kind": "Content",
222-
"text": "(cloudevent: "
222+
"text": "(cloudEvent: "
223223
},
224224
{
225225
"kind": "Reference",
@@ -247,7 +247,7 @@
247247
"overloadIndex": 1,
248248
"parameters": [
249249
{
250-
"parameterName": "cloudevent",
250+
"parameterName": "cloudEvent",
251251
"parameterTypeTokenRange": {
252252
"startIndex": 1,
253253
"endIndex": 2
@@ -261,7 +261,7 @@
261261
{
262262
"kind": "Interface",
263263
"canonicalReference": "@google-cloud/functions-framework!CloudEventFunctionWithCallback:interface",
264-
"docComment": "/**\n * A cloudevent function handler with callback.\n *\n * @public\n */\n",
264+
"docComment": "/**\n * A CloudEvent function handler with callback.\n *\n * @public\n */\n",
265265
"excerptTokens": [
266266
{
267267
"kind": "Content",
@@ -278,7 +278,7 @@
278278
"excerptTokens": [
279279
{
280280
"kind": "Content",
281-
"text": "(cloudevent: "
281+
"text": "(cloudEvent: "
282282
},
283283
{
284284
"kind": "Reference",
@@ -315,7 +315,7 @@
315315
"overloadIndex": 1,
316316
"parameters": [
317317
{
318-
"parameterName": "cloudevent",
318+
"parameterName": "cloudEvent",
319319
"parameterTypeTokenRange": {
320320
"startIndex": 1,
321321
"endIndex": 2

docs/generated/api.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import * as express from 'express';
1010

1111
// @public
12-
export const cloudevent: (functionName: string, handler: CloudEventFunction) => void;
12+
export const cloudEvent: (functionName: string, handler: CloudEventFunction) => void;
1313

1414
// @public
1515
export interface CloudEventFunction {
1616
// (undocumented)
17-
(cloudevent: CloudEventsContext): any;
17+
(cloudEvent: CloudEventsContext): any;
1818
}
1919

2020
// @public
2121
export interface CloudEventFunctionWithCallback {
2222
// (undocumented)
23-
(cloudevent: CloudEventsContext, callback: Function): any;
23+
(cloudEvent: CloudEventsContext, callback: Function): any;
2424
}
2525

2626
// @public

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"conformance": "./run_conformance_tests.sh",
2222
"check": "gts check",
2323
"clean": "gts clean",
24-
"compile": "tsc -p .",
24+
"compile": "rm -rf ./build && tsc -p .",
2525
"fix": "gts fix",
2626
"predocs": "npm run compile",
2727
"docs": "api-extractor run --local --verbose",
File renamed without changes.

src/function_registry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ export const http = (functionName: string, handler: HttpFunction): void => {
6464
/**
6565
* Register a function that handles CloudEvents.
6666
* @param functionName - the name of the function
67-
* @param handler - the function to trigger when handling cloudevents
67+
* @param handler - the function to trigger when handling CloudEvents
6868
* @public
6969
*/
70-
export const cloudevent = (
70+
export const cloudEvent = (
7171
functionName: string,
7272
handler: CloudEventFunction
7373
): void => {

src/function_wrappers.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as domain from 'domain';
1717
import {Request, Response, RequestHandler} from 'express';
1818
import {sendCrashResponse} from './logger';
1919
import {sendResponse} from './invoker';
20-
import {isBinaryCloudEvent, getBinaryCloudEventContext} from './cloudevents';
20+
import {isBinaryCloudEvent, getBinaryCloudEventContext} from './cloud_events';
2121
import {
2222
HttpFunction,
2323
EventFunction,
@@ -56,17 +56,17 @@ const getOnDoneCallback = (res: Response): OnDoneCallback => {
5656
};
5757

5858
/**
59-
* Helper function to parse a cloudevent object from an HTTP request.
59+
* Helper function to parse a CloudEvent object from an HTTP request.
6060
* @param req an Express HTTP request
61-
* @returns a cloudevent parsed from the request
61+
* @returns a CloudEvent parsed from the request
6262
*/
6363
const parseCloudEventRequest = (req: Request): CloudEventsContext => {
64-
let cloudevent = req.body;
64+
let cloudEvent = req.body;
6565
if (isBinaryCloudEvent(req)) {
66-
cloudevent = getBinaryCloudEventContext(req);
67-
cloudevent.data = req.body;
66+
cloudEvent = getBinaryCloudEventContext(req);
67+
cloudEvent.data = req.body;
6868
}
69-
return cloudevent;
69+
return cloudEvent;
7070
};
7171

7272
/**
@@ -119,7 +119,7 @@ const wrapHttpFunction = (execute: HttpFunction): RequestHandler => {
119119
};
120120

121121
/**
122-
* Wraps an async cloudevent function in an express RequestHandler.
122+
* Wraps an async CloudEvent function in an express RequestHandler.
123123
* @param userFunction User's function.
124124
* @return An Express hander function that invokes the user function.
125125
*/
@@ -128,9 +128,9 @@ const wrapCloudEventFunction = (
128128
): RequestHandler => {
129129
const httpHandler = (req: Request, res: Response) => {
130130
const callback = getOnDoneCallback(res);
131-
const cloudevent = parseCloudEventRequest(req);
131+
const cloudEvent = parseCloudEventRequest(req);
132132
Promise.resolve()
133-
.then(() => userFunction(cloudevent))
133+
.then(() => userFunction(cloudEvent))
134134
.then(
135135
result => callback(null, result),
136136
err => callback(err, undefined)
@@ -140,7 +140,7 @@ const wrapCloudEventFunction = (
140140
};
141141

142142
/**
143-
* Wraps callback style cloudevent function in an express RequestHandler.
143+
* Wraps callback style CloudEvent function in an express RequestHandler.
144144
* @param userFunction User's function.
145145
* @return An Express hander function that invokes the user function.
146146
*/
@@ -149,8 +149,8 @@ const wrapCloudEventFunctionWithCallback = (
149149
): RequestHandler => {
150150
const httpHandler = (req: Request, res: Response) => {
151151
const callback = getOnDoneCallback(res);
152-
const cloudevent = parseCloudEventRequest(req);
153-
return userFunction(cloudevent, callback);
152+
const cloudEvent = parseCloudEventRequest(req);
153+
return userFunction(cloudEvent, callback);
154154
};
155155
return wrapHttpFunction(httpHandler);
156156
};

src/functions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ export interface EventFunctionWithCallback {
5555
(data: {}, context: Context, callback: Function): any;
5656
}
5757
/**
58-
* A cloudevent function handler.
58+
* A CloudEvent function handler.
5959
* @public
6060
*/
6161
export interface CloudEventFunction {
62-
(cloudevent: CloudEventsContext): any;
62+
(cloudEvent: CloudEventsContext): any;
6363
}
6464
/**
65-
* A cloudevent function handler with callback.
65+
* A CloudEvent function handler with callback.
6666
* @public
6767
*/
6868
export interface CloudEventFunctionWithCallback {
69-
(cloudevent: CloudEventsContext, callback: Function): any;
69+
(cloudEvent: CloudEventsContext, callback: Function): any;
7070
}
7171
/**
7272
* A function handler.

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ export * from './functions';
2020
/**
2121
* @public
2222
*/
23-
export {http, cloudevent} from './function_registry';
23+
export {http, cloudEvent} from './function_registry';

src/middleware/background_event_to_cloudevent.ts renamed to src/middleware/background_event_to_cloud_event.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
CE_SERVICE,
1717
EventConversionError,
1818
isBinaryCloudEvent,
19-
} from '../cloudevents';
20-
import {CE_TO_BACKGROUND_TYPE} from './cloudevent_to_background_event';
19+
} from '../cloud_events';
20+
import {CE_TO_BACKGROUND_TYPE} from './cloud_event_to_background_event';
2121
import {CloudFunctionsContext, LegacyEvent} from '../functions';
2222

2323
// Maps GCF Event types to the equivalent CloudEventType
@@ -193,7 +193,7 @@ export const backgroundEventToCloudEventMiddleware = (
193193

194194
if (service === CE_SERVICE.FIREBASE_AUTH) {
195195
if ('metadata' in data) {
196-
// Some metadata are not consistent between cloudevents and background events
196+
// Some metadata are not consistent between CloudEvents and background events
197197
const metadata: object = data.metadata;
198198
data.metadata = {};
199199
// eslint-disable-next-line prefer-const
@@ -213,15 +213,15 @@ export const backgroundEventToCloudEventMiddleware = (
213213
const domain = req.body['domain'];
214214
if (!domain) {
215215
throw new EventConversionError(
216-
`Unable convert to ${CE_SERVICE.FIREBASE_DB} cloudevent: invalid domain`
216+
`Unable convert to ${CE_SERVICE.FIREBASE_DB} CloudEvent: invalid domain`
217217
);
218218
}
219219
let location = 'us-central1';
220220
if (domain !== 'firebaseio.com') {
221221
const match = domain.match(/^([\w-]+)\.firebasedatabase\.app$/);
222222
if (!match) {
223223
throw new EventConversionError(
224-
`Unable convert to ${CE_SERVICE.FIREBASE_DB} cloudevent: invalid domain`
224+
`Unable convert to ${CE_SERVICE.FIREBASE_DB} CloudEvent: invalid domain`
225225
);
226226
}
227227
location = match[1];

src/middleware/cloudevent_to_background_event.ts renamed to src/middleware/cloud_event_to_background_event.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
isBinaryCloudEvent,
1818
getBinaryCloudEventContext,
1919
EventConversionError,
20-
} from '../cloudevents';
20+
} from '../cloud_events';
2121

2222
// Maps CloudEvent types to the equivalent GCF Event type
2323
export const CE_TO_BACKGROUND_TYPE: {[k: string]: string} = {
@@ -132,7 +132,7 @@ const marshalConvertableCloudEvent = (
132132
// FirebaseAuth resource format
133133
resource = name;
134134
if ('metadata' in data) {
135-
// Some metadata are not consistent between cloudevents and legacy events
135+
// Some metadata are not consistent between CloudEvents and legacy events
136136
const metadata: object = data.metadata;
137137
data.metadata = {};
138138
// eslint-disable-next-line prefer-const
@@ -177,7 +177,7 @@ const marshalConvertableCloudEvent = (
177177
* @param res express response object
178178
* @param next function used to pass control to the next middle middleware function in the stack
179179
*/
180-
export const cloudeventToBackgroundEventMiddleware = (
180+
export const cloudEventToBackgroundEventMiddleware = (
181181
req: Request,
182182
res: Response,
183183
next: NextFunction

src/pubsub_middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
import {Request, Response, NextFunction} from 'express';
15-
import {isBinaryCloudEvent} from './cloudevents';
15+
import {isBinaryCloudEvent} from './cloud_events';
1616

1717
const PUBSUB_EVENT_TYPE = 'google.pubsub.topic.publish';
1818
const PUBSUB_MESSAGE_TYPE =

src/server.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import {HandlerFunction, Request, Response} from './functions';
2020
import {SignatureType} from './types';
2121
import {setLatestRes} from './invoker';
2222
import {legacyPubSubEventMiddleware} from './pubsub_middleware';
23-
import {cloudeventToBackgroundEventMiddleware} from './middleware/cloudevent_to_background_event';
24-
import {backgroundEventToCloudEventMiddleware} from './middleware/background_event_to_cloudevent';
23+
import {cloudEventToBackgroundEventMiddleware} from './middleware/cloud_event_to_background_event';
24+
import {backgroundEventToCloudEventMiddleware} from './middleware/background_event_to_cloud_event';
2525
import {wrapUserFunction} from './function_wrappers';
2626

2727
/**
@@ -108,7 +108,7 @@ export function getServer(
108108
}
109109

110110
if (functionSignatureType === 'event') {
111-
app.use(cloudeventToBackgroundEventMiddleware);
111+
app.use(cloudEventToBackgroundEventMiddleware);
112112
}
113113
if (functionSignatureType === 'cloudevent') {
114114
app.use(backgroundEventToCloudEventMiddleware);

test/conformance/function.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ functions.http('writeHttpDeclarative', (req, res) => {
88
res.end(200);
99
});
1010

11-
functions.cloudevent('writeCloudEventDeclarative', cloudevent => {
12-
cloudevent.datacontenttype = 'application/json';
13-
writeJson(cloudevent);
11+
functions.cloudEvent('writeCloudEventDeclarative', cloudEvent => {
12+
cloudEvent.datacontenttype = 'application/json';
13+
writeJson(cloudEvent);
1414
});
1515

1616
function writeHttp(req, res) {
1717
writeJson(req.body);
1818
res.end(200);
1919
}
2020

21-
function writeCloudEvent(cloudevent) {
22-
cloudevent.datacontenttype = 'application/json';
23-
writeJson(cloudevent);
21+
function writeCloudEvent(cloudEvent) {
22+
cloudEvent.datacontenttype = 'application/json';
23+
writeJson(cloudEvent);
2424
}
2525

2626
function writeLegacyEvent(data, context) {

test/function_registry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('function_registry', () => {
2525
assert.deepStrictEqual((userFunction as () => string)(), 'HTTP_PASS');
2626
});
2727

28-
it('can register cloudevent functions', () => {
29-
FunctionRegistry.cloudevent('ceFunction', () => 'CE_PASS');
28+
it('can register CloudEvent functions', () => {
29+
FunctionRegistry.cloudEvent('ceFunction', () => 'CE_PASS');
3030
const {
3131
userFunction,
3232
signatureType,

0 commit comments

Comments
 (0)