export type MaybePromise = T | Promise; export type JsonPrimitive = string | number | boolean | null; export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }; export type JsonObject = { [key: string]: JsonValue }; export type ControllerConditionStatus = true | false | "unknown"; export type ControllerCondition = { type: string; status: ControllerConditionStatus; reason: string; message?: string; observedGeneration: number; lastTransitionTime: string; }; export type ChildWorkflowState = | "pending" | "running" | "waiting" | "succeeded" | "failed" | "interrupted"; export type ChildWorkflowReference = { requestId: string; runId?: string; state: ChildWorkflowState; attempt: number; }; export type ControllerResourceStatus = { observedGeneration: number; conditions: ControllerCondition[]; controllerStatus: TStatus; workflowRun?: ChildWorkflowReference; }; export type ControllerResource = { metadata: { uid: string; controller: string; key: string; resourceVersion: number; generation: number; deletionTimestamp?: string; finalizers: string[]; }; spec: TSpec; status: ControllerResourceStatus; }; export type ControllerResourceRef = { controller: string; key: string; }; export type ControllerConditionInput = { type: string; status: ControllerConditionStatus; reason: string; message?: string; }; export type ControllerStatusPatch = { controllerStatus?: TStatus; conditions?: ControllerConditionInput[]; workflowRun?: ChildWorkflowReference | null; finalizers?: string[]; }; export type ReconcileResult = | { kind: "settled"; status?: ControllerStatusPatch; } | { kind: "requeue"; afterMs?: number; status?: ControllerStatusPatch; }; export type EffectState = "pending" | "applied" | "rejected" | "indeterminate"; export type EffectRecord = { key: string; resourceUid: string; generation: number; kind: string; state: EffectState; requestFingerprint: string; startedAt: string; completedAt?: string; externalRef?: string; error?: string; }; export type EffectObservation = | { state: "applied"; externalRef?: string } | { state: "not_applied" } | { state: "indeterminate" }; export type EffectApplication = | { state: "applied"; externalRef?: string } | { state: "rejected"; error: string } | { state: "indeterminate"; error?: string }; export type EffectDefinition = { key: string; kind: string; request: TRequest; observe: (signal: AbortSignal) => MaybePromise; apply: (signal: AbortSignal) => MaybePromise; }; export interface ControllerEffects { ensure(definition: EffectDefinition): Promise; } export type ChildWorkflowRequest = { requestKey: string; workflow: string; input: unknown; }; export type ChildWorkflowRecord = ChildWorkflowReference & { resourceUid: string; requestKey: string; inputFingerprint: string; workflow: string; error?: string; }; export interface ControllerWorkflows { ensure(request: ChildWorkflowRequest): Promise; } export type ReconcileContext = { signal: AbortSignal; effects: ControllerEffects; workflows: ControllerWorkflows; settled(status?: ControllerStatusPatch): ReconcileResult; requeue(status?: ControllerStatusPatch): ReconcileResult; requeueAfter(afterMs: number, status?: ControllerStatusPatch): ReconcileResult; }; export type ControllerDefinition = { name: string; initialStatus: (spec: TSpec) => TStatus; reconcile: ( context: ReconcileContext, resource: ControllerResource, ) => MaybePromise>; timeoutMs?: number; }; export type AnyControllerDefinition = { name: string; initialStatus(spec: unknown): unknown; reconcile( context: ReconcileContext, resource: ControllerResource, ): MaybePromise>; timeoutMs?: number; }; export type ControllerQueueClaim = { controller: string; key: string; token: string; queueVersion: number; consecutiveErrors: number; expiresAt: string; }; export type ControllerEvent = { seq: number; recordedAt: string; controller: string; key: string; type: string; payload: JsonObject; };