Skip to content
Open
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
80 changes: 80 additions & 0 deletions types/defines/event-subscriptions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
type EventSubscriptionEvent<
Service extends string,
Type extends string,
Source,
Payload = {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably default to Record<string, never> instead? (assuming this is meant to be an empty object)

> = {
type: `cf.${Service}.${Type}`;
source: { service: Service } & Source;
payload: Payload;
metadata: {
accountId: string;
eventId: string;
eventSubscriptionId: string;
eventTimestamp: string; // RFC3339 timestamp
eventSchemaVersion: 1;
};
};

// Super Slurper
export type EventMessageSuperSlurper =
| EventSubscriptionEvent<"superSlurper", "jobStarted", { jobId: string }>
| EventSubscriptionEvent<"superSlurper", "jobPaused", { jobId: string }>
| EventSubscriptionEvent<"superSlurper", "jobResumed", { jobId: string }>
| EventSubscriptionEvent<
"superSlurper",
"jobFinished",
{ jobId: string },
{
totalObjectsCount: number;
migratedObjectsCount: number;
failedObjectsCount: number;
}
>
| EventSubscriptionEvent<"superSlurper", "jobAborted", { jobId: string }>;

// Workflows
type SubscriptionEventSourceWorkflows = {
workflowId: string;
workflowName: string;
versionId: string;
instanceId: string;
};
Comment on lines +37 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird that workflows has a helper for this, but superSlurper doesn't. Since this type will be exposed to users, I wonder if we should inline it?

export type EventMessageWorkflows =
| EventSubscriptionEvent<
"workflows",
"instanceQueued",
SubscriptionEventSourceWorkflows
>
| EventSubscriptionEvent<
"workflows",
"instanceStarted",
SubscriptionEventSourceWorkflows
>
| EventSubscriptionEvent<
"workflows",
"instancePaused",
SubscriptionEventSourceWorkflows
>
| EventSubscriptionEvent<
"workflows",
"instanceResumed",
SubscriptionEventSourceWorkflows
>
| EventSubscriptionEvent<
"workflows",
"instanceErrored",
SubscriptionEventSourceWorkflows
>
| EventSubscriptionEvent<
"workflows",
"instanceTerminated",
SubscriptionEventSourceWorkflows
>
| EventSubscriptionEvent<
"workflows",
"instanceFinished",
SubscriptionEventSourceWorkflows
>;

export type EventMessage = EventMessageSuperSlurper | EventMessageWorkflows;
Loading