Skip to content

Commit

Permalink
refactor!: use snake case for generated cloudevent files
Browse files Browse the repository at this point in the history
This is consistent with other filenames in the project.
  • Loading branch information
matthewrobertson committed Nov 6, 2021
1 parent 81ba122 commit 6f1db6c
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 141 deletions.
2 changes: 1 addition & 1 deletion experimental/generate_cloud_events/README.md
Expand Up @@ -8,4 +8,4 @@ It can be run via the following command:
npm run generate_cloudevents
```

This will regenerate all known CloudEvent type interfaces in the `src/cloudevent_types` directory of this repository.
This will regenerate all known CloudEvent type interfaces in the `src/cloud_event_types` directory of this repository.
2 changes: 1 addition & 1 deletion experimental/generate_cloud_events/package.json
Expand Up @@ -5,7 +5,7 @@
"main": "build/src/index.js",
"dependencies": {},
"scripts": {
"generate_cloudevents": "ts-node ./src/generate.ts && gts fix ../../src/cloudevent_types/**/*.ts"
"generate_cloudevents": "ts-node ./src/generate.ts && gts fix ../../src/cloud_event_types/**/*.ts"
},
"files": [
"build/src/**/*.js",
Expand Down
13 changes: 9 additions & 4 deletions experimental/generate_cloud_events/src/generate.ts
Expand Up @@ -116,8 +116,13 @@ const generateInterfaceBody = (properties: {
*/
const generateCloudEventImport = (): t.Statement => {
return t.importDeclaration(
[t.importSpecifier(t.identifier('CloudEvent'), t.identifier('CloudEvent'))],
t.stringLiteral('./CloudEvent')
[
t.importSpecifier(
t.identifier('CloudEventsContext'),
t.identifier('CloudEventsContext')
),
],
t.stringLiteral('./cloud_events_context')
);
};

Expand Down Expand Up @@ -156,7 +161,7 @@ const generateCloudEventInterface = (schema: TypeSchema): t.Statement => {
t.tsInterfaceDeclaration(
t.identifier(schema.name.replace(/Data$/, 'CloudEvent')),
null,
[t.tsExpressionWithTypeArguments(t.identifier('CloudEvent'))],
[t.tsExpressionWithTypeArguments(t.identifier('CloudEventsContext'))],
t.tsInterfaceBody([
t.tsPropertySignature(
t.identifier('type'),
Expand Down Expand Up @@ -248,6 +253,6 @@ utils.fetch(ROOT_TYPE_CATALOG_URL).then(catalog => {
utils.addCopyright(ast);

const {code} = generate(ast);
fs.writeFileSync(utils.RELATIVE_SRC_DIR + '/GoogleCloudEvent.ts', code);
fs.writeFileSync(utils.RELATIVE_SRC_DIR + '/google_cloud_event.ts', code);
});
});
8 changes: 6 additions & 2 deletions experimental/generate_cloud_events/src/utils.ts
Expand Up @@ -19,7 +19,7 @@ import * as https from 'https';
/**
* Relative path of src dictory to write the TS files ts.
*/
export const RELATIVE_SRC_DIR = '../../src/cloudevent_types';
export const RELATIVE_SRC_DIR = '../../src/cloud_event_types';

/**
* Add a JSDoc comment to an AST node
Expand Down Expand Up @@ -72,7 +72,11 @@ export const fetch = (url: string): Promise<{[key: string]: any}> => {
export const getDataFilePath = (url: string): string => {
return (
RELATIVE_SRC_DIR +
url.split('jsonschema/google/events')[1].replace('.json', '.ts')
url
.split('jsonschema/google/events')[1]
.replace('.json', '.ts')
.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`)
.replace('/_', '/')
);
};

Expand Down
54 changes: 0 additions & 54 deletions src/cloud_event_types/CloudEvent.ts

This file was deleted.

63 changes: 63 additions & 0 deletions src/cloud_event_types/cloud_events_context.ts
@@ -0,0 +1,63 @@
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* The CloudEvents v1.0 context attributes.
* {@link https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#context-attributes}
* @public
*/
export interface CloudEventsContext {
/**
* ID of the event.
*/
id: string;
/**
* The event producer.
*/
source: string;
/**
* The version of the CloudEvents specification which the event uses.
*/
specversion: string;
/**
* Type of occurrence which has happened.
*/
type: string;
/**
* Timestamp of when the event happened.
*/
time?: string;
/**
* Describes the subject of the event in the context of the event producer.
*/
subject?: string;
/**
* A link to the schema that the event data adheres to.
*/
dataschema?: string;
/**
* Content type of the event data.
*/
datacontenttype?: string;
/**
* The traceparent string, containing a trace version, trace ID, span ID, and trace options.
* @see https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md
*/
traceparent?: string;
/**
* The event payload.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: any;
}
Expand Up @@ -13,25 +13,25 @@
// limitations under the License.

/* eslint-disable @typescript-eslint/no-explicit-any*/
import {LogEntryData} from './cloud/audit/v1/LogEntryData';
import {BuildEventData} from './cloud/cloudbuild/v1/BuildEventData';
import {DocumentEventData} from './cloud/firestore/v1/DocumentEventData';
import {MessagePublishedData} from './cloud/pubsub/v1/MessagePublishedData';
import {SchedulerJobData} from './cloud/scheduler/v1/SchedulerJobData';
import {StorageObjectData} from './cloud/storage/v1/StorageObjectData';
import {AnalyticsLogData} from './firebase/analytics/v1/AnalyticsLogData';
import {AuthEventData} from './firebase/auth/v1/AuthEventData';
import {ReferenceEventData} from './firebase/database/v1/ReferenceEventData';
import {RemoteConfigEventData} from './firebase/remoteconfig/v1/RemoteConfigEventData';
import {TestMatrixEventData} from './firebase/testlab/v1/TestMatrixEventData';
import {CloudEvent} from './CloudEvent';
import {LogEntryData} from './cloud/audit/v1/log_entry_data';
import {BuildEventData} from './cloud/cloudbuild/v1/build_event_data';
import {DocumentEventData} from './cloud/firestore/v1/document_event_data';
import {MessagePublishedData} from './cloud/pubsub/v1/message_published_data';
import {SchedulerJobData} from './cloud/scheduler/v1/scheduler_job_data';
import {StorageObjectData} from './cloud/storage/v1/storage_object_data';
import {AnalyticsLogData} from './firebase/analytics/v1/analytics_log_data';
import {AuthEventData} from './firebase/auth/v1/auth_event_data';
import {ReferenceEventData} from './firebase/database/v1/reference_event_data';
import {RemoteConfigEventData} from './firebase/remoteconfig/v1/remote_config_event_data';
import {TestMatrixEventData} from './firebase/testlab/v1/test_matrix_event_data';
import {CloudEventsContext} from './cloud_events_context';

/**
* The schema of CloudEvents emmitted by Cloud Audit Logs.
*
* @public
*/
export interface LogEntryCloudEvent extends CloudEvent {
export interface LogEntryCloudEvent extends CloudEventsContext {
type: 'google.cloud.audit.log.v1.written';
data: LogEntryData;
}
Expand All @@ -41,7 +41,7 @@ export interface LogEntryCloudEvent extends CloudEvent {
*
* @public
*/
export interface BuildEventCloudEvent extends CloudEvent {
export interface BuildEventCloudEvent extends CloudEventsContext {
type: 'google.cloud.cloudbuild.build.v1.statusChanged';
data: BuildEventData;
}
Expand All @@ -51,7 +51,7 @@ export interface BuildEventCloudEvent extends CloudEvent {
*
* @public
*/
export interface DocumentEventCloudEvent extends CloudEvent {
export interface DocumentEventCloudEvent extends CloudEventsContext {
type:
| 'google.cloud.firestore.document.v1.created'
| 'google.cloud.firestore.document.v1.updated'
Expand All @@ -65,7 +65,7 @@ export interface DocumentEventCloudEvent extends CloudEvent {
*
* @public
*/
export interface MessagePublishedCloudEvent extends CloudEvent {
export interface MessagePublishedCloudEvent extends CloudEventsContext {
type: 'google.cloud.pubsub.topic.v1.messagePublished';
data: MessagePublishedData;
}
Expand All @@ -75,7 +75,7 @@ export interface MessagePublishedCloudEvent extends CloudEvent {
*
* @public
*/
export interface SchedulerJobCloudEvent extends CloudEvent {
export interface SchedulerJobCloudEvent extends CloudEventsContext {
type: 'google.cloud.scheduler.job.v1.executed';
data: SchedulerJobData;
}
Expand All @@ -85,7 +85,7 @@ export interface SchedulerJobCloudEvent extends CloudEvent {
*
* @public
*/
export interface StorageObjectCloudEvent extends CloudEvent {
export interface StorageObjectCloudEvent extends CloudEventsContext {
type:
| 'google.cloud.storage.object.v1.finalized'
| 'google.cloud.storage.object.v1.archived'
Expand All @@ -99,7 +99,7 @@ export interface StorageObjectCloudEvent extends CloudEvent {
*
* @public
*/
export interface AnalyticsLogCloudEvent extends CloudEvent {
export interface AnalyticsLogCloudEvent extends CloudEventsContext {
type: 'google.firebase.analytics.log.v1.written';
data: AnalyticsLogData;
}
Expand All @@ -109,7 +109,7 @@ export interface AnalyticsLogCloudEvent extends CloudEvent {
*
* @public
*/
export interface AuthEventCloudEvent extends CloudEvent {
export interface AuthEventCloudEvent extends CloudEventsContext {
type:
| 'google.firebase.auth.user.v1.created'
| 'google.firebase.auth.user.v1.deleted';
Expand All @@ -121,7 +121,7 @@ export interface AuthEventCloudEvent extends CloudEvent {
*
* @public
*/
export interface ReferenceEventCloudEvent extends CloudEvent {
export interface ReferenceEventCloudEvent extends CloudEventsContext {
type:
| 'google.firebase.database.ref.v1.created'
| 'google.firebase.database.ref.v1.updated'
Expand All @@ -135,7 +135,7 @@ export interface ReferenceEventCloudEvent extends CloudEvent {
*
* @public
*/
export interface RemoteConfigEventCloudEvent extends CloudEvent {
export interface RemoteConfigEventCloudEvent extends CloudEventsContext {
type: 'google.firebase.remoteconfig.remoteConfig.v1.updated';
data: RemoteConfigEventData;
}
Expand All @@ -145,7 +145,7 @@ export interface RemoteConfigEventCloudEvent extends CloudEvent {
*
* @public
*/
export interface TestMatrixEventCloudEvent extends CloudEvent {
export interface TestMatrixEventCloudEvent extends CloudEventsContext {
type: 'google.firebase.testlab.testMatrix.v1.completed';
data: TestMatrixEventData;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cloud_events.ts
Expand Up @@ -59,7 +59,7 @@ export function isBinaryCloudEvent(req: express.Request): boolean {
export function getBinaryCloudEventContext(
req: express.Request
): CloudEventsContext {
const context: CloudEventsContext = {};
const context = {} as CloudEventsContext;
for (const name in req.headers) {
if (name.startsWith('ce-')) {
const attributeName = name.substr(
Expand Down

0 comments on commit 6f1db6c

Please sign in to comment.