Skip to content

Commit f67d11d

Browse files
authored
feat: updates event and cloudevent interfaces (#276)
- Updates the function interfaces for the Node FF - Adds a `LegacyEvent` interface - Updates `CloudEvent` interface to CE 1.0 (must have been <1.0 with `schemaurl`)
1 parent 6b8e664 commit f67d11d

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/cloudevents.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ export function getBinaryCloudEventContext(
4747
const context: CloudEventsContext = {};
4848
for (const name in req.headers) {
4949
if (name.startsWith('ce-')) {
50-
const attributeName = name.substr('ce-'.length);
50+
const attributeName = name.substr(
51+
'ce-'.length
52+
) as keyof CloudEventsContext;
5153
context[attributeName] = req.header(name);
5254
}
5355
}

src/functions.ts

+30-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ export type HandlerFunction =
4040
| CloudEventFunction
4141
| CloudEventFunctionWithCallback;
4242

43+
/**
44+
* A legacy event.
45+
*/
46+
export interface LegacyEvent {
47+
data: object;
48+
context: CloudFunctionsContext;
49+
}
50+
51+
interface Data {
52+
data: object;
53+
}
54+
export type LegacyCloudFunctionsContext = CloudFunctionsContext | Data;
55+
4356
/**
4457
* The Cloud Functions context object for the event.
4558
*
@@ -62,7 +75,7 @@ export interface CloudFunctionsContext {
6275
/**
6376
* The resource that emitted the event.
6477
*/
65-
resource?: string;
78+
resource?: string | object;
6679
}
6780

6881
/**
@@ -91,17 +104,28 @@ export interface CloudEventsContext {
91104
* Timestamp of when the event happened.
92105
*/
93106
time?: string;
107+
/**
108+
* Describes the subject of the event in the context of the event producer.
109+
*/
110+
subject?: string;
94111
/**
95112
* A link to the schema that the event data adheres to.
96113
*/
97-
schemaurl?: string;
114+
dataschema?: string;
98115
/**
99116
* Content type of the event data.
100117
*/
101-
contenttype?: string;
102-
103-
// CloudEvents extension attributes.
104-
[key: string]: any;
118+
datacontenttype?: string;
119+
/**
120+
* The event data.
121+
*/
122+
data?:
123+
| Record<string, unknown | string | number | boolean>
124+
| string
125+
| number
126+
| boolean
127+
| null
128+
| unknown;
105129
}
106130

107131
export type Context = CloudFunctionsContext | CloudEventsContext;

0 commit comments

Comments
 (0)