Skip to content

Commit

Permalink
refactor!: use snake case for generated cloudevent files (#382)
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 05a0527
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 177 deletions.
28 changes: 14 additions & 14 deletions docs/generated/api.d.ts
Expand Up @@ -27,27 +27,27 @@ export declare interface CloudEventFunctionWithCallback {
}

/**
* The CloudEvents v1.0 context object for the event.
* {@link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes}
* The CloudEvents v1.0 context attributes.
* {@link https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#context-attributes}
* @public
*/
export declare interface CloudEventsContext {
/**
* Type of occurrence which has happened.
* ID of the event.
*/
type?: string;
id: string;
/**
* The version of the CloudEvents specification which the event uses.
* The event producer.
*/
specversion?: string;
source: string;
/**
* The event producer.
* The version of the CloudEvents specification which the event uses.
*/
source?: string;
specversion: string;
/**
* ID of the event.
* Type of occurrence which has happened.
*/
id?: string;
type: string;
/**
* Timestamp of when the event happened.
*/
Expand All @@ -64,15 +64,15 @@ export declare interface CloudEventsContext {
* Content type of the event data.
*/
datacontenttype?: string;
/**
* The event data.
*/
data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown;
/**
* 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.
*/
data?: any;
}

/**
Expand Down
29 changes: 12 additions & 17 deletions docs/generated/api.json
Expand Up @@ -336,7 +336,7 @@
{
"kind": "Interface",
"canonicalReference": "@google-cloud/functions-framework!CloudEventsContext:interface",
"docComment": "/**\n * The CloudEvents v1.0 context object for the event. {@link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes}\n *\n * @public\n */\n",
"docComment": "/**\n * The CloudEvents v1.0 context attributes. {@link https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#context-attributes}\n *\n * @public\n */\n",
"excerptTokens": [
{
"kind": "Content",
Expand All @@ -349,20 +349,15 @@
{
"kind": "PropertySignature",
"canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#data:member",
"docComment": "/**\n * The event data.\n */\n",
"docComment": "/**\n * The event payload.\n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "data?: "
},
{
"kind": "Reference",
"text": "Record",
"canonicalReference": "!Record:type"
},
{
"kind": "Content",
"text": "<string, unknown | string | number | boolean> | string | number | boolean | null | unknown"
"text": "any"
},
{
"kind": "Content",
Expand All @@ -374,7 +369,7 @@
"name": "data",
"propertyTypeTokenRange": {
"startIndex": 1,
"endIndex": 3
"endIndex": 2
}
},
{
Expand Down Expand Up @@ -436,7 +431,7 @@
"excerptTokens": [
{
"kind": "Content",
"text": "id?: "
"text": "id: "
},
{
"kind": "Content",
Expand All @@ -447,7 +442,7 @@
"text": ";"
}
],
"isOptional": true,
"isOptional": false,
"releaseTag": "Public",
"name": "id",
"propertyTypeTokenRange": {
Expand All @@ -462,7 +457,7 @@
"excerptTokens": [
{
"kind": "Content",
"text": "source?: "
"text": "source: "
},
{
"kind": "Content",
Expand All @@ -473,7 +468,7 @@
"text": ";"
}
],
"isOptional": true,
"isOptional": false,
"releaseTag": "Public",
"name": "source",
"propertyTypeTokenRange": {
Expand All @@ -488,7 +483,7 @@
"excerptTokens": [
{
"kind": "Content",
"text": "specversion?: "
"text": "specversion: "
},
{
"kind": "Content",
Expand All @@ -499,7 +494,7 @@
"text": ";"
}
],
"isOptional": true,
"isOptional": false,
"releaseTag": "Public",
"name": "specversion",
"propertyTypeTokenRange": {
Expand Down Expand Up @@ -592,7 +587,7 @@
"excerptTokens": [
{
"kind": "Content",
"text": "type?: "
"text": "type: "
},
{
"kind": "Content",
Expand All @@ -603,7 +598,7 @@
"text": ";"
}
],
"isOptional": true,
"isOptional": false,
"releaseTag": "Public",
"name": "type",
"propertyTypeTokenRange": {
Expand Down
10 changes: 5 additions & 5 deletions docs/generated/api.md
Expand Up @@ -25,16 +25,16 @@ export interface CloudEventFunctionWithCallback {

// @public
export interface CloudEventsContext {
data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown;
data?: any;
datacontenttype?: string;
dataschema?: string;
id?: string;
source?: string;
specversion?: string;
id: string;
source: string;
specversion: string;
subject?: string;
time?: string;
traceparent?: string;
type?: string;
type: string;
}

// @public
Expand Down
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;
}

0 comments on commit 05a0527

Please sign in to comment.