From 2b9a35bae094dd58725ab5d0ed235b399b380ed5 Mon Sep 17 00:00:00 2001 From: Siddhant Sinha Date: Thu, 27 Mar 2025 13:10:33 -0400 Subject: [PATCH] add types for event-subscriptions --- types/defines/event-subscriptions.d.ts | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 types/defines/event-subscriptions.d.ts diff --git a/types/defines/event-subscriptions.d.ts b/types/defines/event-subscriptions.d.ts new file mode 100644 index 00000000000..a4fde0d7a6f --- /dev/null +++ b/types/defines/event-subscriptions.d.ts @@ -0,0 +1,80 @@ +type EventSubscriptionEvent< + Service extends string, + Type extends string, + Source, + Payload = {}, +> = { + 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; +}; +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;