Skip to content

Commit 6f1db6c

Browse files
refactor!: use snake case for generated cloudevent files
This is consistent with other filenames in the project.
1 parent 81ba122 commit 6f1db6c

File tree

20 files changed

+110
-141
lines changed

20 files changed

+110
-141
lines changed

experimental/generate_cloud_events/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ It can be run via the following command:
88
npm run generate_cloudevents
99
```
1010

11-
This will regenerate all known CloudEvent type interfaces in the `src/cloudevent_types` directory of this repository.
11+
This will regenerate all known CloudEvent type interfaces in the `src/cloud_event_types` directory of this repository.

experimental/generate_cloud_events/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "build/src/index.js",
66
"dependencies": {},
77
"scripts": {
8-
"generate_cloudevents": "ts-node ./src/generate.ts && gts fix ../../src/cloudevent_types/**/*.ts"
8+
"generate_cloudevents": "ts-node ./src/generate.ts && gts fix ../../src/cloud_event_types/**/*.ts"
99
},
1010
"files": [
1111
"build/src/**/*.js",

experimental/generate_cloud_events/src/generate.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ const generateInterfaceBody = (properties: {
116116
*/
117117
const generateCloudEventImport = (): t.Statement => {
118118
return t.importDeclaration(
119-
[t.importSpecifier(t.identifier('CloudEvent'), t.identifier('CloudEvent'))],
120-
t.stringLiteral('./CloudEvent')
119+
[
120+
t.importSpecifier(
121+
t.identifier('CloudEventsContext'),
122+
t.identifier('CloudEventsContext')
123+
),
124+
],
125+
t.stringLiteral('./cloud_events_context')
121126
);
122127
};
123128

@@ -156,7 +161,7 @@ const generateCloudEventInterface = (schema: TypeSchema): t.Statement => {
156161
t.tsInterfaceDeclaration(
157162
t.identifier(schema.name.replace(/Data$/, 'CloudEvent')),
158163
null,
159-
[t.tsExpressionWithTypeArguments(t.identifier('CloudEvent'))],
164+
[t.tsExpressionWithTypeArguments(t.identifier('CloudEventsContext'))],
160165
t.tsInterfaceBody([
161166
t.tsPropertySignature(
162167
t.identifier('type'),
@@ -248,6 +253,6 @@ utils.fetch(ROOT_TYPE_CATALOG_URL).then(catalog => {
248253
utils.addCopyright(ast);
249254

250255
const {code} = generate(ast);
251-
fs.writeFileSync(utils.RELATIVE_SRC_DIR + '/GoogleCloudEvent.ts', code);
256+
fs.writeFileSync(utils.RELATIVE_SRC_DIR + '/google_cloud_event.ts', code);
252257
});
253258
});

experimental/generate_cloud_events/src/utils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as https from 'https';
1919
/**
2020
* Relative path of src dictory to write the TS files ts.
2121
*/
22-
export const RELATIVE_SRC_DIR = '../../src/cloudevent_types';
22+
export const RELATIVE_SRC_DIR = '../../src/cloud_event_types';
2323

2424
/**
2525
* Add a JSDoc comment to an AST node
@@ -72,7 +72,11 @@ export const fetch = (url: string): Promise<{[key: string]: any}> => {
7272
export const getDataFilePath = (url: string): string => {
7373
return (
7474
RELATIVE_SRC_DIR +
75-
url.split('jsonschema/google/events')[1].replace('.json', '.ts')
75+
url
76+
.split('jsonschema/google/events')[1]
77+
.replace('.json', '.ts')
78+
.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`)
79+
.replace('/_', '/')
7680
);
7781
};
7882

src/cloud_event_types/CloudEvent.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* The CloudEvents v1.0 context attributes.
17+
* {@link https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#context-attributes}
18+
* @public
19+
*/
20+
export interface CloudEventsContext {
21+
/**
22+
* ID of the event.
23+
*/
24+
id: string;
25+
/**
26+
* The event producer.
27+
*/
28+
source: string;
29+
/**
30+
* The version of the CloudEvents specification which the event uses.
31+
*/
32+
specversion: string;
33+
/**
34+
* Type of occurrence which has happened.
35+
*/
36+
type: string;
37+
/**
38+
* Timestamp of when the event happened.
39+
*/
40+
time?: string;
41+
/**
42+
* Describes the subject of the event in the context of the event producer.
43+
*/
44+
subject?: string;
45+
/**
46+
* A link to the schema that the event data adheres to.
47+
*/
48+
dataschema?: string;
49+
/**
50+
* Content type of the event data.
51+
*/
52+
datacontenttype?: string;
53+
/**
54+
* The traceparent string, containing a trace version, trace ID, span ID, and trace options.
55+
* @see https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md
56+
*/
57+
traceparent?: string;
58+
/**
59+
* The event payload.
60+
*/
61+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
62+
data?: any;
63+
}

src/cloud_event_types/GoogleCloudEvent.ts renamed to src/cloud_event_types/google_cloud_event.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
// limitations under the License.
1414

1515
/* eslint-disable @typescript-eslint/no-explicit-any*/
16-
import {LogEntryData} from './cloud/audit/v1/LogEntryData';
17-
import {BuildEventData} from './cloud/cloudbuild/v1/BuildEventData';
18-
import {DocumentEventData} from './cloud/firestore/v1/DocumentEventData';
19-
import {MessagePublishedData} from './cloud/pubsub/v1/MessagePublishedData';
20-
import {SchedulerJobData} from './cloud/scheduler/v1/SchedulerJobData';
21-
import {StorageObjectData} from './cloud/storage/v1/StorageObjectData';
22-
import {AnalyticsLogData} from './firebase/analytics/v1/AnalyticsLogData';
23-
import {AuthEventData} from './firebase/auth/v1/AuthEventData';
24-
import {ReferenceEventData} from './firebase/database/v1/ReferenceEventData';
25-
import {RemoteConfigEventData} from './firebase/remoteconfig/v1/RemoteConfigEventData';
26-
import {TestMatrixEventData} from './firebase/testlab/v1/TestMatrixEventData';
27-
import {CloudEvent} from './CloudEvent';
16+
import {LogEntryData} from './cloud/audit/v1/log_entry_data';
17+
import {BuildEventData} from './cloud/cloudbuild/v1/build_event_data';
18+
import {DocumentEventData} from './cloud/firestore/v1/document_event_data';
19+
import {MessagePublishedData} from './cloud/pubsub/v1/message_published_data';
20+
import {SchedulerJobData} from './cloud/scheduler/v1/scheduler_job_data';
21+
import {StorageObjectData} from './cloud/storage/v1/storage_object_data';
22+
import {AnalyticsLogData} from './firebase/analytics/v1/analytics_log_data';
23+
import {AuthEventData} from './firebase/auth/v1/auth_event_data';
24+
import {ReferenceEventData} from './firebase/database/v1/reference_event_data';
25+
import {RemoteConfigEventData} from './firebase/remoteconfig/v1/remote_config_event_data';
26+
import {TestMatrixEventData} from './firebase/testlab/v1/test_matrix_event_data';
27+
import {CloudEventsContext} from './cloud_events_context';
2828

2929
/**
3030
* The schema of CloudEvents emmitted by Cloud Audit Logs.
3131
*
3232
* @public
3333
*/
34-
export interface LogEntryCloudEvent extends CloudEvent {
34+
export interface LogEntryCloudEvent extends CloudEventsContext {
3535
type: 'google.cloud.audit.log.v1.written';
3636
data: LogEntryData;
3737
}
@@ -41,7 +41,7 @@ export interface LogEntryCloudEvent extends CloudEvent {
4141
*
4242
* @public
4343
*/
44-
export interface BuildEventCloudEvent extends CloudEvent {
44+
export interface BuildEventCloudEvent extends CloudEventsContext {
4545
type: 'google.cloud.cloudbuild.build.v1.statusChanged';
4646
data: BuildEventData;
4747
}
@@ -51,7 +51,7 @@ export interface BuildEventCloudEvent extends CloudEvent {
5151
*
5252
* @public
5353
*/
54-
export interface DocumentEventCloudEvent extends CloudEvent {
54+
export interface DocumentEventCloudEvent extends CloudEventsContext {
5555
type:
5656
| 'google.cloud.firestore.document.v1.created'
5757
| 'google.cloud.firestore.document.v1.updated'
@@ -65,7 +65,7 @@ export interface DocumentEventCloudEvent extends CloudEvent {
6565
*
6666
* @public
6767
*/
68-
export interface MessagePublishedCloudEvent extends CloudEvent {
68+
export interface MessagePublishedCloudEvent extends CloudEventsContext {
6969
type: 'google.cloud.pubsub.topic.v1.messagePublished';
7070
data: MessagePublishedData;
7171
}
@@ -75,7 +75,7 @@ export interface MessagePublishedCloudEvent extends CloudEvent {
7575
*
7676
* @public
7777
*/
78-
export interface SchedulerJobCloudEvent extends CloudEvent {
78+
export interface SchedulerJobCloudEvent extends CloudEventsContext {
7979
type: 'google.cloud.scheduler.job.v1.executed';
8080
data: SchedulerJobData;
8181
}
@@ -85,7 +85,7 @@ export interface SchedulerJobCloudEvent extends CloudEvent {
8585
*
8686
* @public
8787
*/
88-
export interface StorageObjectCloudEvent extends CloudEvent {
88+
export interface StorageObjectCloudEvent extends CloudEventsContext {
8989
type:
9090
| 'google.cloud.storage.object.v1.finalized'
9191
| 'google.cloud.storage.object.v1.archived'
@@ -99,7 +99,7 @@ export interface StorageObjectCloudEvent extends CloudEvent {
9999
*
100100
* @public
101101
*/
102-
export interface AnalyticsLogCloudEvent extends CloudEvent {
102+
export interface AnalyticsLogCloudEvent extends CloudEventsContext {
103103
type: 'google.firebase.analytics.log.v1.written';
104104
data: AnalyticsLogData;
105105
}
@@ -109,7 +109,7 @@ export interface AnalyticsLogCloudEvent extends CloudEvent {
109109
*
110110
* @public
111111
*/
112-
export interface AuthEventCloudEvent extends CloudEvent {
112+
export interface AuthEventCloudEvent extends CloudEventsContext {
113113
type:
114114
| 'google.firebase.auth.user.v1.created'
115115
| 'google.firebase.auth.user.v1.deleted';
@@ -121,7 +121,7 @@ export interface AuthEventCloudEvent extends CloudEvent {
121121
*
122122
* @public
123123
*/
124-
export interface ReferenceEventCloudEvent extends CloudEvent {
124+
export interface ReferenceEventCloudEvent extends CloudEventsContext {
125125
type:
126126
| 'google.firebase.database.ref.v1.created'
127127
| 'google.firebase.database.ref.v1.updated'
@@ -135,7 +135,7 @@ export interface ReferenceEventCloudEvent extends CloudEvent {
135135
*
136136
* @public
137137
*/
138-
export interface RemoteConfigEventCloudEvent extends CloudEvent {
138+
export interface RemoteConfigEventCloudEvent extends CloudEventsContext {
139139
type: 'google.firebase.remoteconfig.remoteConfig.v1.updated';
140140
data: RemoteConfigEventData;
141141
}
@@ -145,7 +145,7 @@ export interface RemoteConfigEventCloudEvent extends CloudEvent {
145145
*
146146
* @public
147147
*/
148-
export interface TestMatrixEventCloudEvent extends CloudEvent {
148+
export interface TestMatrixEventCloudEvent extends CloudEventsContext {
149149
type: 'google.firebase.testlab.testMatrix.v1.completed';
150150
data: TestMatrixEventData;
151151
}

src/cloud_events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function isBinaryCloudEvent(req: express.Request): boolean {
5959
export function getBinaryCloudEventContext(
6060
req: express.Request
6161
): CloudEventsContext {
62-
const context: CloudEventsContext = {};
62+
const context = {} as CloudEventsContext;
6363
for (const name in req.headers) {
6464
if (name.startsWith('ce-')) {
6565
const attributeName = name.substr(

0 commit comments

Comments
 (0)