From 3d12c24e8dd472bd5a28f07c35e781bc21d520af Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 21 Apr 2021 12:48:41 -0500 Subject: [PATCH 1/3] feat: updates event and cloudevent interfaces Signed-off-by: Grant Timmerman --- src/functions.ts | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/functions.ts b/src/functions.ts index 91f4f6d9..bedf5505 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -40,6 +40,19 @@ export type HandlerFunction = | CloudEventFunction | CloudEventFunctionWithCallback; +/** + * A legacy event. + */ +export interface LegacyEvent { + data: object; + context: CloudFunctionsContext; +} + +interface Data { + data: object; +} +export type LegacyCloudFunctionsContext = CloudFunctionsContext | Data; + /** * The Cloud Functions context object for the event. * @@ -62,7 +75,7 @@ export interface CloudFunctionsContext { /** * The resource that emitted the event. */ - resource?: string; + resource?: string | object; } /** @@ -91,17 +104,28 @@ export interface CloudEventsContext { * 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. */ - schemaurl?: string; + dataschema?: string; /** * Content type of the event data. */ - contenttype?: string; - - // CloudEvents extension attributes. - [key: string]: any; + datacontenttype?: string; + /** + * The event data. + */ + data?: + | Record + | string + | number + | boolean + | null + | unknown; } export type Context = CloudFunctionsContext | CloudEventsContext; From affd10f02957711ce688cd9fbf2f0d5d54f73981 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 21 Apr 2021 15:20:10 -0500 Subject: [PATCH 2/3] ci: fix interface assertion Signed-off-by: Grant Timmerman --- src/cloudevents.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cloudevents.ts b/src/cloudevents.ts index 1b9eaa2f..0ae91269 100644 --- a/src/cloudevents.ts +++ b/src/cloudevents.ts @@ -47,7 +47,7 @@ export function getBinaryCloudEventContext( const context: CloudEventsContext = {}; for (const name in req.headers) { if (name.startsWith('ce-')) { - const attributeName = name.substr('ce-'.length); + const attributeName = name.substr('ce-'.length) as keyof CloudEventsContext; context[attributeName] = req.header(name); } } From 7b1eb54bb692e08c5338749d901180ad852831d9 Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Wed, 21 Apr 2021 15:25:10 -0500 Subject: [PATCH 3/3] ci: run npm run fix Signed-off-by: Grant Timmerman --- src/cloudevents.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cloudevents.ts b/src/cloudevents.ts index 0ae91269..1d28fbe3 100644 --- a/src/cloudevents.ts +++ b/src/cloudevents.ts @@ -47,7 +47,9 @@ export function getBinaryCloudEventContext( const context: CloudEventsContext = {}; for (const name in req.headers) { if (name.startsWith('ce-')) { - const attributeName = name.substr('ce-'.length) as keyof CloudEventsContext; + const attributeName = name.substr( + 'ce-'.length + ) as keyof CloudEventsContext; context[attributeName] = req.header(name); } }