Skip to content

Commit 05a0527

Browse files
refactor!: use snake case for generated cloudevent files (#382)
This is consistent with other filenames in the project.
1 parent 81ba122 commit 05a0527

File tree

23 files changed

+141
-177
lines changed

23 files changed

+141
-177
lines changed

docs/generated/api.d.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@ export declare interface CloudEventFunctionWithCallback {
2727
}
2828

2929
/**
30-
* The CloudEvents v1.0 context object for the event.
31-
* {@link https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes}
30+
* The CloudEvents v1.0 context attributes.
31+
* {@link https://github.com/cloudevents/spec/blob/v1.0.1/spec.md#context-attributes}
3232
* @public
3333
*/
3434
export declare interface CloudEventsContext {
3535
/**
36-
* Type of occurrence which has happened.
36+
* ID of the event.
3737
*/
38-
type?: string;
38+
id: string;
3939
/**
40-
* The version of the CloudEvents specification which the event uses.
40+
* The event producer.
4141
*/
42-
specversion?: string;
42+
source: string;
4343
/**
44-
* The event producer.
44+
* The version of the CloudEvents specification which the event uses.
4545
*/
46-
source?: string;
46+
specversion: string;
4747
/**
48-
* ID of the event.
48+
* Type of occurrence which has happened.
4949
*/
50-
id?: string;
50+
type: string;
5151
/**
5252
* Timestamp of when the event happened.
5353
*/
@@ -64,15 +64,15 @@ export declare interface CloudEventsContext {
6464
* Content type of the event data.
6565
*/
6666
datacontenttype?: string;
67-
/**
68-
* The event data.
69-
*/
70-
data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown;
7167
/**
7268
* The traceparent string, containing a trace version, trace ID, span ID, and trace options.
7369
* @see https://github.com/cloudevents/spec/blob/master/extensions/distributed-tracing.md
7470
*/
7571
traceparent?: string;
72+
/**
73+
* The event payload.
74+
*/
75+
data?: any;
7676
}
7777

7878
/**

docs/generated/api.json

+12-17
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@
336336
{
337337
"kind": "Interface",
338338
"canonicalReference": "@google-cloud/functions-framework!CloudEventsContext:interface",
339-
"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",
339+
"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",
340340
"excerptTokens": [
341341
{
342342
"kind": "Content",
@@ -349,20 +349,15 @@
349349
{
350350
"kind": "PropertySignature",
351351
"canonicalReference": "@google-cloud/functions-framework!CloudEventsContext#data:member",
352-
"docComment": "/**\n * The event data.\n */\n",
352+
"docComment": "/**\n * The event payload.\n */\n",
353353
"excerptTokens": [
354354
{
355355
"kind": "Content",
356356
"text": "data?: "
357357
},
358-
{
359-
"kind": "Reference",
360-
"text": "Record",
361-
"canonicalReference": "!Record:type"
362-
},
363358
{
364359
"kind": "Content",
365-
"text": "<string, unknown | string | number | boolean> | string | number | boolean | null | unknown"
360+
"text": "any"
366361
},
367362
{
368363
"kind": "Content",
@@ -374,7 +369,7 @@
374369
"name": "data",
375370
"propertyTypeTokenRange": {
376371
"startIndex": 1,
377-
"endIndex": 3
372+
"endIndex": 2
378373
}
379374
},
380375
{
@@ -436,7 +431,7 @@
436431
"excerptTokens": [
437432
{
438433
"kind": "Content",
439-
"text": "id?: "
434+
"text": "id: "
440435
},
441436
{
442437
"kind": "Content",
@@ -447,7 +442,7 @@
447442
"text": ";"
448443
}
449444
],
450-
"isOptional": true,
445+
"isOptional": false,
451446
"releaseTag": "Public",
452447
"name": "id",
453448
"propertyTypeTokenRange": {
@@ -462,7 +457,7 @@
462457
"excerptTokens": [
463458
{
464459
"kind": "Content",
465-
"text": "source?: "
460+
"text": "source: "
466461
},
467462
{
468463
"kind": "Content",
@@ -473,7 +468,7 @@
473468
"text": ";"
474469
}
475470
],
476-
"isOptional": true,
471+
"isOptional": false,
477472
"releaseTag": "Public",
478473
"name": "source",
479474
"propertyTypeTokenRange": {
@@ -488,7 +483,7 @@
488483
"excerptTokens": [
489484
{
490485
"kind": "Content",
491-
"text": "specversion?: "
486+
"text": "specversion: "
492487
},
493488
{
494489
"kind": "Content",
@@ -499,7 +494,7 @@
499494
"text": ";"
500495
}
501496
],
502-
"isOptional": true,
497+
"isOptional": false,
503498
"releaseTag": "Public",
504499
"name": "specversion",
505500
"propertyTypeTokenRange": {
@@ -592,7 +587,7 @@
592587
"excerptTokens": [
593588
{
594589
"kind": "Content",
595-
"text": "type?: "
590+
"text": "type: "
596591
},
597592
{
598593
"kind": "Content",
@@ -603,7 +598,7 @@
603598
"text": ";"
604599
}
605600
],
606-
"isOptional": true,
601+
"isOptional": false,
607602
"releaseTag": "Public",
608603
"name": "type",
609604
"propertyTypeTokenRange": {

docs/generated/api.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ export interface CloudEventFunctionWithCallback {
2525

2626
// @public
2727
export interface CloudEventsContext {
28-
data?: Record<string, unknown | string | number | boolean> | string | number | boolean | null | unknown;
28+
data?: any;
2929
datacontenttype?: string;
3030
dataschema?: string;
31-
id?: string;
32-
source?: string;
33-
specversion?: string;
31+
id: string;
32+
source: string;
33+
specversion: string;
3434
subject?: string;
3535
time?: string;
3636
traceparent?: string;
37-
type?: string;
37+
type: string;
3838
}
3939

4040
// @public

experimental/generate_cloud_events/README.md

+1-1
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

+1-1
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

+9-4
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

+6-2
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

-54
This file was deleted.
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+
}

0 commit comments

Comments
 (0)