Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cloudevents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
const attributeName = name.substr(
'ce-'.length
) as keyof CloudEventsContext;
context[attributeName] = req.header(name);
}
}
Expand Down
36 changes: 30 additions & 6 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -62,7 +75,7 @@ export interface CloudFunctionsContext {
/**
* The resource that emitted the event.
*/
resource?: string;
resource?: string | object;
}

/**
Expand Down Expand Up @@ -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, unknown | string | number | boolean>
| string
| number
| boolean
| null
| unknown;
}

export type Context = CloudFunctionsContext | CloudEventsContext;