@aikirun/types 0.5.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -3,20 +3,21 @@ import { WorkflowRun, WorkflowRunId } from './workflow-run.js';
3
3
  import { WorkflowRunApi } from './workflow-run-api.js';
4
4
  import { INTERNAL } from './symbols.js';
5
5
  import './error.js';
6
- import './retry.js';
7
- import './sleep.js';
6
+ import './event.js';
8
7
  import './duration.js';
9
8
  import './utils.js';
9
+ import './retry.js';
10
+ import './sleep.js';
10
11
  import './task.js';
11
12
  import './trigger.js';
12
13
 
13
- interface ClientParams<AppContext> {
14
+ interface ClientParams<AppContext = unknown> {
14
15
  url: string;
15
16
  redis: RedisConfig;
16
17
  logger?: Logger;
17
18
  contextFactory?: (run: Readonly<WorkflowRun>) => AppContext | Promise<AppContext>;
18
19
  }
19
- interface Client<AppContext> {
20
+ interface Client<AppContext = unknown> {
20
21
  api: ApiClient;
21
22
  logger: Logger;
22
23
  close: () => Promise<void>;
package/dist/error.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- type SerializableInput = null | string | number | boolean | {
2
- [key: string]: SerializableInput;
3
- } | SerializableInput[];
1
+ type Serializable = null | string | number | boolean | {
2
+ [key: string]: Serializable;
3
+ } | Serializable[];
4
4
  interface SerializableError {
5
5
  message: string;
6
6
  name: string;
@@ -8,4 +8,4 @@ interface SerializableError {
8
8
  cause?: SerializableError;
9
9
  }
10
10
 
11
- export type { SerializableError, SerializableInput };
11
+ export type { Serializable, SerializableError };
@@ -0,0 +1,40 @@
1
+ import { DurationObject } from './duration.js';
2
+ import './utils.js';
3
+
4
+ type EventId = string & {
5
+ _brand: "event_id";
6
+ };
7
+ type EventStatus = "received" | "timeout";
8
+ interface EventStateBase {
9
+ status: EventStatus;
10
+ }
11
+ interface EventStateReceived<Data> extends EventStateBase {
12
+ status: "received";
13
+ data: Data;
14
+ receivedAt: number;
15
+ idempotencyKey?: string;
16
+ }
17
+ interface EventStateTimeout extends EventStateBase {
18
+ status: "timeout";
19
+ timedOutAt: number;
20
+ }
21
+ type EventState<Data> = EventStateReceived<Data> | EventStateTimeout;
22
+ interface EventQueue<Data> {
23
+ events: EventState<Data>[];
24
+ }
25
+ interface EventWaitOptions<Timed extends boolean> {
26
+ timeout?: Timed extends true ? DurationObject : never;
27
+ }
28
+ type EventWaitState<Data, Timed extends boolean> = Timed extends false ? {
29
+ data: Data;
30
+ } : {
31
+ timeout: false;
32
+ data: Data;
33
+ } | {
34
+ timeout: true;
35
+ };
36
+ interface EventSendOptions {
37
+ idempotencyKey?: string;
38
+ }
39
+
40
+ export type { EventId, EventQueue, EventSendOptions, EventState, EventStateReceived, EventStateTimeout, EventStatus, EventWaitOptions, EventWaitState };
package/dist/event.js ADDED
File without changes
package/dist/task.d.ts CHANGED
@@ -6,7 +6,7 @@ type TaskId = string & {
6
6
  type TaskPath = string & {
7
7
  _brand: "task_path";
8
8
  };
9
- type TaskStatus = "none" | "running" | "completed" | "failed";
9
+ type TaskStatus = "none" | "running" | "awaiting_retry" | "completed" | "failed";
10
10
  interface TaskStateBase {
11
11
  status: TaskStatus;
12
12
  }
@@ -17,19 +17,22 @@ interface TaskStateRunning extends TaskStateBase {
17
17
  status: "running";
18
18
  attempts: number;
19
19
  }
20
+ interface TaskStateAwaitingRetry extends TaskStateBase {
21
+ status: "awaiting_retry";
22
+ attempts: number;
23
+ error: SerializableError;
24
+ nextAttemptAt: number;
25
+ }
20
26
  interface TaskStateCompleted<Output> extends TaskStateBase {
21
27
  status: "completed";
22
28
  output: Output;
23
29
  }
24
30
  interface TaskStateFailed extends TaskStateBase {
25
31
  status: "failed";
26
- reason: string;
27
32
  attempts: number;
28
- attemptedAt: number;
29
- nextAttemptAt?: number;
30
- error?: SerializableError;
33
+ error: SerializableError;
31
34
  }
32
- type TaskState<Output> = TaskStateNone | TaskStateRunning | TaskStateCompleted<Output> | TaskStateFailed;
35
+ type TaskState<Output = unknown> = TaskStateNone | TaskStateRunning | TaskStateAwaitingRetry | TaskStateCompleted<Output> | TaskStateFailed;
33
36
  declare class TaskFailedError extends Error {
34
37
  readonly taskPath: TaskPath;
35
38
  readonly attempts: number;
@@ -37,4 +40,4 @@ declare class TaskFailedError extends Error {
37
40
  constructor(taskPath: TaskPath, attempts: number, reason: string);
38
41
  }
39
42
 
40
- export { TaskFailedError, type TaskId, type TaskPath, type TaskState, type TaskStateCompleted, type TaskStateFailed, type TaskStateNone, type TaskStateRunning, type TaskStatus };
43
+ export { TaskFailedError, type TaskId, type TaskPath, type TaskState, type TaskStateAwaitingRetry, type TaskStateCompleted, type TaskStateFailed, type TaskStateNone, type TaskStateRunning, type TaskStatus };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  type RequireAtLeastOneOf<T, Keys extends keyof T> = {
2
2
  [K in Keys]-?: Required<Pick<T, K>> & Omit<T, K>;
3
3
  }[Keys];
4
+ type DistributiveOmit<T, K extends keyof T> = T extends T ? Omit<T, K> : never;
4
5
 
5
- export type { RequireAtLeastOneOf };
6
+ export type { DistributiveOmit, RequireAtLeastOneOf };
@@ -1,10 +1,11 @@
1
- import { TaskState } from './task.js';
2
- import { WorkflowRunStatus, WorkflowRun, WorkflowRunState, WorkflowOptions, WorkflowRunStateScheduled, WorkflowRunStateScheduledByNew, WorkflowRunStateScheduledByResume, WorkflowRunStatePaused, WorkflowRunStateCancelled, WorkflowRunTransition } from './workflow-run.js';
1
+ import { EventSendOptions } from './event.js';
2
+ import { TaskState, TaskStateAwaitingRetry } from './task.js';
3
+ import { DistributiveOmit } from './utils.js';
4
+ import { WorkflowRunStatus, WorkflowRun, WorkflowRunState, WorkflowOptions, WorkflowRunStateScheduled, WorkflowRunStateAwaitingEvent, WorkflowRunStateAwaitingRetry, WorkflowRunStateAwaitingChildWorkflow, WorkflowRunStatePaused, WorkflowRunStateCancelled, WorkflowRunTransition } from './workflow-run.js';
5
+ import './duration.js';
3
6
  import './error.js';
4
7
  import './retry.js';
5
8
  import './sleep.js';
6
- import './duration.js';
7
- import './utils.js';
8
9
  import './trigger.js';
9
10
 
10
11
  interface WorkflowRunApi {
@@ -15,6 +16,8 @@ interface WorkflowRunApi {
15
16
  transitionStateV1: (input: WorkflowRunTransitionStateRequestV1) => Promise<WorkflowRunTransitionStateResponseV1>;
16
17
  transitionTaskStateV1: (input: WorkflowRunTransitionTaskStateRequestV1) => Promise<WorkflowRunTransitionTaskStateResponseV1>;
17
18
  listTransitionsV1: (input: WorkflowRunListTransitionsRequestV1) => Promise<WorkflowRunListTransitionsResponseV1>;
19
+ sendEventV1: (input: WorkflowRunSendEventRequestV1) => Promise<WorkflowRunSendEventResponseV1>;
20
+ multicastEventV1: (input: WorkflowRunMulticastEventRequestV1) => Promise<void>;
18
21
  }
19
22
  interface WorkflowRunListRequestV1 {
20
23
  limit?: number;
@@ -52,43 +55,68 @@ interface WorkflowRunGetStateRequestV1 {
52
55
  id: string;
53
56
  }
54
57
  interface WorkflowRunGetStateResponseV1 {
55
- state: WorkflowRunState<unknown>;
58
+ state: WorkflowRunState;
56
59
  }
57
60
  interface WorkflowRunCreateRequestV1 {
58
61
  workflowId: string;
59
62
  workflowVersionId: string;
60
63
  input: unknown;
64
+ path?: string;
65
+ parentWorkflowRunId?: string;
61
66
  options?: WorkflowOptions;
62
67
  }
63
68
  interface WorkflowRunCreateResponseV1 {
64
69
  run: WorkflowRun;
65
70
  }
71
+ type WorkflowRunStateScheduledRequest = DistributiveOmit<WorkflowRunStateScheduled, "scheduledAt"> & {
72
+ scheduledInMs: number;
73
+ };
74
+ type WorkflowRunStateAwaitingEventRequest = DistributiveOmit<WorkflowRunStateAwaitingEvent, "timeoutAt"> & {
75
+ timeoutInMs?: number;
76
+ };
77
+ type WorkflowRunStateAwaitingRetryRequest = DistributiveOmit<WorkflowRunStateAwaitingRetry, "nextAttemptAt"> & {
78
+ nextAttemptInMs: number;
79
+ };
80
+ type WorkflowRunStateAwaitingChildWorkflowRequest = DistributiveOmit<WorkflowRunStateAwaitingChildWorkflow, "timeoutAt"> & {
81
+ timeoutInMs?: number;
82
+ };
83
+ type WorkflowRunStateRequest = Exclude<WorkflowRunState, {
84
+ status: "scheduled" | "awaiting_event" | "awaiting_retry" | "awaiting_child_workflow";
85
+ }> | WorkflowRunStateScheduledRequest | WorkflowRunStateAwaitingEventRequest | WorkflowRunStateAwaitingRetryRequest | WorkflowRunStateAwaitingChildWorkflowRequest;
66
86
  interface WorkflowRunTransitionStateRequestBase {
67
87
  type: "optimistic" | "pessimistic";
68
88
  id: string;
69
- state: WorkflowRunState<unknown>;
89
+ state: WorkflowRunStateRequest;
70
90
  }
91
+ type WorkflowRunStateScheduledRequestOptimistic = Extract<WorkflowRunStateScheduledRequest, {
92
+ reason: "retry" | "task_retry" | "event" | "child_workflow";
93
+ }>;
94
+ type WorkflowRunStateScheduledRequestPessimistic = Exclude<WorkflowRunStateScheduledRequest, WorkflowRunStateScheduledRequestOptimistic>;
71
95
  interface WorkflowRunTransitionStateRequestOptimistic extends WorkflowRunTransitionStateRequestBase {
72
96
  type: "optimistic";
73
- state: Exclude<WorkflowRunState<unknown>, {
97
+ state: WorkflowRunStateScheduledRequestOptimistic | Exclude<WorkflowRunStateRequest, {
74
98
  status: "scheduled" | "paused" | "cancelled";
75
- }> | Exclude<WorkflowRunStateScheduled, {
76
- reason: "new" | "resume";
77
99
  }>;
78
100
  expectedRevision: number;
79
101
  }
80
102
  interface WorkflowRunTransitionStateRequestPessimistic extends WorkflowRunTransitionStateRequestBase {
81
103
  type: "pessimistic";
82
- state: WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByResume | WorkflowRunStatePaused | WorkflowRunStateCancelled;
104
+ state: WorkflowRunStateScheduledRequestPessimistic | WorkflowRunStatePaused | WorkflowRunStateCancelled;
83
105
  }
84
106
  type WorkflowRunTransitionStateRequestV1 = WorkflowRunTransitionStateRequestOptimistic | WorkflowRunTransitionStateRequestPessimistic;
85
107
  interface WorkflowRunTransitionStateResponseV1 {
86
108
  run: WorkflowRun;
87
109
  }
110
+ type TaskStateAwaitingRetryRequest = DistributiveOmit<TaskStateAwaitingRetry, "nextAttemptAt"> & {
111
+ nextAttemptInMs: number;
112
+ };
113
+ type TaskStateRequest = Exclude<TaskState, {
114
+ status: "awaiting_retry";
115
+ }> | TaskStateAwaitingRetryRequest;
88
116
  interface WorkflowRunTransitionTaskStateRequestV1 {
89
117
  id: string;
90
118
  taskPath: string;
91
- taskState: TaskState<unknown>;
119
+ taskState: TaskStateRequest;
92
120
  expectedRevision: number;
93
121
  }
94
122
  interface WorkflowRunTransitionTaskStateResponseV1 {
@@ -107,5 +135,20 @@ interface WorkflowRunListTransitionsResponseV1 {
107
135
  transitions: WorkflowRunTransition[];
108
136
  total: number;
109
137
  }
138
+ interface WorkflowRunSendEventRequestV1 {
139
+ id: string;
140
+ eventId: string;
141
+ data: unknown;
142
+ options?: EventSendOptions;
143
+ }
144
+ interface WorkflowRunSendEventResponseV1 {
145
+ run: WorkflowRun;
146
+ }
147
+ interface WorkflowRunMulticastEventRequestV1 {
148
+ ids: string[];
149
+ eventId: string;
150
+ data: unknown;
151
+ options?: EventSendOptions;
152
+ }
110
153
 
111
- export type { WorkflowRunApi, WorkflowRunCreateRequestV1, WorkflowRunCreateResponseV1, WorkflowRunGetByIdRequestV1, WorkflowRunGetByIdResponseV1, WorkflowRunGetStateRequestV1, WorkflowRunGetStateResponseV1, WorkflowRunListItem, WorkflowRunListRequestV1, WorkflowRunListResponseV1, WorkflowRunListTransitionsRequestV1, WorkflowRunListTransitionsResponseV1, WorkflowRunTransitionStateRequestV1, WorkflowRunTransitionStateResponseV1, WorkflowRunTransitionTaskStateRequestV1, WorkflowRunTransitionTaskStateResponseV1 };
154
+ export type { TaskStateAwaitingRetryRequest, TaskStateRequest, WorkflowRunApi, WorkflowRunCreateRequestV1, WorkflowRunCreateResponseV1, WorkflowRunGetByIdRequestV1, WorkflowRunGetByIdResponseV1, WorkflowRunGetStateRequestV1, WorkflowRunGetStateResponseV1, WorkflowRunListItem, WorkflowRunListRequestV1, WorkflowRunListResponseV1, WorkflowRunListTransitionsRequestV1, WorkflowRunListTransitionsResponseV1, WorkflowRunMulticastEventRequestV1, WorkflowRunSendEventRequestV1, WorkflowRunSendEventResponseV1, WorkflowRunStateAwaitingChildWorkflowRequest, WorkflowRunStateAwaitingEventRequest, WorkflowRunStateAwaitingRetryRequest, WorkflowRunStateRequest, WorkflowRunStateScheduledRequest, WorkflowRunStateScheduledRequestOptimistic, WorkflowRunStateScheduledRequestPessimistic, WorkflowRunTransitionStateRequestOptimistic, WorkflowRunTransitionStateRequestPessimistic, WorkflowRunTransitionStateRequestV1, WorkflowRunTransitionStateResponseV1, WorkflowRunTransitionTaskStateRequestV1, WorkflowRunTransitionTaskStateResponseV1 };
@@ -1,4 +1,5 @@
1
1
  import { SerializableError } from './error.js';
2
+ import { EventQueue } from './event.js';
2
3
  import { RetryStrategy } from './retry.js';
3
4
  import { SleepState } from './sleep.js';
4
5
  import { TaskState } from './task.js';
@@ -9,9 +10,14 @@ import './utils.js';
9
10
  type WorkflowRunId = string & {
10
11
  _brand: "workflow_run_id";
11
12
  };
13
+ type WorkflowRunPath = string & {
14
+ _brand: "workflow_run_path";
15
+ };
12
16
  type WorkflowRunStatus = "scheduled" | "queued" | "running" | "paused" | "sleeping" | "awaiting_event" | "awaiting_retry" | "awaiting_child_workflow" | "cancelled" | "completed" | "failed";
13
- type TerminalWorkflowRunStatus = "cancelled" | "completed" | "failed";
17
+ declare const terminalWorkflowRunStatuses: readonly ["cancelled", "completed", "failed"];
18
+ type TerminalWorkflowRunStatus = (typeof terminalWorkflowRunStatuses)[number];
14
19
  type NonTerminalWorkflowRunStatus = Exclude<WorkflowRunStatus, TerminalWorkflowRunStatus>;
20
+ declare function isTerminalWorkflowRunStatus(status: WorkflowRunStatus): status is TerminalWorkflowRunStatus;
15
21
  interface WorkflowOptions {
16
22
  retry?: RetryStrategy;
17
23
  idempotencyKey?: string;
@@ -21,7 +27,7 @@ interface WorkflowOptions {
21
27
  interface WorkflowRunStateBase {
22
28
  status: WorkflowRunStatus;
23
29
  }
24
- type WorkflowRunScheduledReason = "new" | "retry" | "awake" | "resume" | "event";
30
+ type WorkflowRunScheduledReason = "new" | "retry" | "task_retry" | "awake" | "resume" | "event" | "child_workflow";
25
31
  interface WorkflowRunStateScheduledBase extends WorkflowRunStateBase {
26
32
  status: "scheduled";
27
33
  scheduledAt: number;
@@ -33,6 +39,9 @@ interface WorkflowRunStateScheduledByNew extends WorkflowRunStateScheduledBase {
33
39
  interface WorkflowRunStateScheduledByRetry extends WorkflowRunStateScheduledBase {
34
40
  reason: "retry";
35
41
  }
42
+ interface WorkflowRunStateScheduledByTaskRetry extends WorkflowRunStateScheduledBase {
43
+ reason: "task_retry";
44
+ }
36
45
  interface WorkflowRunStateScheduledByAwake extends WorkflowRunStateScheduledBase {
37
46
  reason: "awake";
38
47
  }
@@ -42,7 +51,10 @@ interface WorkflowRunStateScheduledByResume extends WorkflowRunStateScheduledBas
42
51
  interface WorkflowRunStateScheduledByEvent extends WorkflowRunStateScheduledBase {
43
52
  reason: "event";
44
53
  }
45
- type WorkflowRunStateScheduled = WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByRetry | WorkflowRunStateScheduledByAwake | WorkflowRunStateScheduledByResume | WorkflowRunStateScheduledByEvent;
54
+ interface WorkflowRunStateScheduledByChildWorkflow extends WorkflowRunStateScheduledBase {
55
+ reason: "child_workflow";
56
+ }
57
+ type WorkflowRunStateScheduled = WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByRetry | WorkflowRunStateScheduledByTaskRetry | WorkflowRunStateScheduledByAwake | WorkflowRunStateScheduledByResume | WorkflowRunStateScheduledByEvent | WorkflowRunStateScheduledByChildWorkflow;
46
58
  interface WorkflowRunStateQueued extends WorkflowRunStateBase {
47
59
  status: "queued";
48
60
  reason: WorkflowRunScheduledReason;
@@ -52,7 +64,6 @@ interface WorkflowRunStateRunning extends WorkflowRunStateBase {
52
64
  }
53
65
  interface WorkflowRunStatePaused extends WorkflowRunStateBase {
54
66
  status: "paused";
55
- pausedAt: number;
56
67
  }
57
68
  interface WorkflowRunStateSleeping extends WorkflowRunStateBase {
58
69
  status: "sleeping";
@@ -61,29 +72,33 @@ interface WorkflowRunStateSleeping extends WorkflowRunStateBase {
61
72
  }
62
73
  interface WorkflowRunStateAwaitingEvent extends WorkflowRunStateBase {
63
74
  status: "awaiting_event";
75
+ eventId: string;
76
+ timeoutAt?: number;
64
77
  }
65
78
  type WorkflowFailureCause = "task" | "child_workflow" | "self";
66
- interface WorkflowRunStateAwaitingBase extends WorkflowRunStateBase {
79
+ interface WorkflowRunStateAwaitingRetryBase extends WorkflowRunStateBase {
67
80
  status: "awaiting_retry";
68
81
  cause: WorkflowFailureCause;
69
- reason: string;
70
82
  nextAttemptAt: number;
71
83
  }
72
- interface WorkflowRunStateAwaitingRetryCausedByTask extends WorkflowRunStateAwaitingBase {
84
+ interface WorkflowRunStateAwaitingRetryCausedByTask extends WorkflowRunStateAwaitingRetryBase {
73
85
  cause: "task";
74
86
  taskPath: string;
75
87
  }
76
- interface WorkflowRunStateAwaitingRetryCausedByChildWorkflow extends WorkflowRunStateAwaitingBase {
88
+ interface WorkflowRunStateAwaitingRetryCausedByChildWorkflow extends WorkflowRunStateAwaitingRetryBase {
77
89
  cause: "child_workflow";
78
90
  childWorkflowRunId: string;
79
91
  }
80
- interface WorkflowRunStateAwaitingRetryCausedBySelf extends WorkflowRunStateAwaitingBase {
92
+ interface WorkflowRunStateAwaitingRetryCausedBySelf extends WorkflowRunStateAwaitingRetryBase {
81
93
  cause: "self";
82
94
  error: SerializableError;
83
95
  }
84
96
  type WorkflowRunStateAwaitingRetry = WorkflowRunStateAwaitingRetryCausedByTask | WorkflowRunStateAwaitingRetryCausedByChildWorkflow | WorkflowRunStateAwaitingRetryCausedBySelf;
85
97
  interface WorkflowRunStateAwaitingChildWorkflow extends WorkflowRunStateBase {
86
98
  status: "awaiting_child_workflow";
99
+ childWorkflowRunPath: string;
100
+ childWorkflowRunStatus: WorkflowRunStatus;
101
+ timeoutAt?: number;
87
102
  }
88
103
  interface WorkflowRunStateCancelled extends WorkflowRunStateBase {
89
104
  status: "cancelled";
@@ -96,7 +111,6 @@ interface WorkflowRunStateCompleted<Output> extends WorkflowRunStateBase {
96
111
  interface WorkflowRunStateFailedBase extends WorkflowRunStateBase {
97
112
  status: "failed";
98
113
  cause: WorkflowFailureCause;
99
- reason: string;
100
114
  }
101
115
  interface WorkflowRunStateFailedByTask extends WorkflowRunStateFailedBase {
102
116
  cause: "task";
@@ -112,7 +126,7 @@ interface WorkflowRunStateFailedBySelf extends WorkflowRunStateFailedBase {
112
126
  }
113
127
  type WorkflowRunStateFailed = WorkflowRunStateFailedByTask | WorkflowRunStateFailedByChildWorkflow | WorkflowRunStateFailedBySelf;
114
128
  type WorkflowRunStateInComplete = WorkflowRunStateScheduled | WorkflowRunStateQueued | WorkflowRunStateRunning | WorkflowRunStatePaused | WorkflowRunStateSleeping | WorkflowRunStateAwaitingEvent | WorkflowRunStateAwaitingRetry | WorkflowRunStateAwaitingChildWorkflow | WorkflowRunStateCancelled | WorkflowRunStateFailed;
115
- type WorkflowRunState<Output> = WorkflowRunStateInComplete | WorkflowRunStateCompleted<Output>;
129
+ type WorkflowRunState<Output = unknown> = WorkflowRunStateInComplete | WorkflowRunStateCompleted<Output>;
116
130
  interface WorkflowRun<Input = unknown, Output = unknown> {
117
131
  id: string;
118
132
  workflowId: string;
@@ -120,12 +134,29 @@ interface WorkflowRun<Input = unknown, Output = unknown> {
120
134
  createdAt: number;
121
135
  revision: number;
122
136
  input: Input;
137
+ path?: string;
123
138
  options: WorkflowOptions;
124
139
  attempts: number;
125
140
  state: WorkflowRunState<Output>;
126
- tasksState: Record<string, TaskState<unknown>>;
141
+ tasksState: Record<string, TaskState>;
127
142
  sleepsState: Record<string, SleepState>;
128
- childWorkflowsRunState: Record<string, WorkflowRunState<unknown>>;
143
+ eventsQueue: Record<string, EventQueue<unknown>>;
144
+ childWorkflowRuns: Record<string, ChildWorkflowRun>;
145
+ parentWorkflowRunId?: string;
146
+ }
147
+ interface ChildWorkflowRun {
148
+ id: string;
149
+ statusWaitResults: ChildWorkflowWaitResult[];
150
+ }
151
+ type ChildWorkflowWaitResult = ChildWorkflowWaitResultCompleted | ChildWorkflowWaitResultTimeout;
152
+ interface ChildWorkflowWaitResultCompleted {
153
+ status: "completed";
154
+ completedAt: number;
155
+ childWorkflowRunState: WorkflowRunState;
156
+ }
157
+ interface ChildWorkflowWaitResultTimeout {
158
+ status: "timeout";
159
+ timedOutAt: number;
129
160
  }
130
161
  interface WorkflowRunTransitionBase {
131
162
  createdAt: number;
@@ -133,41 +164,27 @@ interface WorkflowRunTransitionBase {
133
164
  }
134
165
  interface WorkflowRunStateTransition extends WorkflowRunTransitionBase {
135
166
  type: "state";
136
- state: WorkflowRunState<unknown>;
167
+ state: WorkflowRunState;
137
168
  }
138
169
  interface WorkflowRunTaskStateTransition extends WorkflowRunTransitionBase {
139
170
  type: "task_state";
140
171
  taskPath: string;
141
- taskState: TaskState<unknown>;
172
+ taskState: TaskState;
142
173
  }
143
174
  type WorkflowRunTransition = WorkflowRunStateTransition | WorkflowRunTaskStateTransition;
144
- declare class WorkflowRunConflictError extends Error {
145
- readonly id: WorkflowRunId;
146
- readonly operation: string;
147
- readonly attempts: number;
148
- constructor(id: WorkflowRunId, operation: string, attempts: number);
149
- }
150
175
  declare class WorkflowRunNotExecutableError extends Error {
151
176
  readonly id: WorkflowRunId;
152
177
  readonly status: WorkflowRunStatus;
153
178
  constructor(id: WorkflowRunId, status: WorkflowRunStatus);
154
179
  }
155
- declare class WorkflowRunPausedError extends Error {
156
- constructor(id: WorkflowRunId);
157
- }
158
- declare class WorkflowRunCancelledError extends Error {
180
+ declare class WorkflowRunSuspendedError extends Error {
181
+ readonly id: WorkflowRunId;
159
182
  constructor(id: WorkflowRunId);
160
183
  }
161
184
  declare class WorkflowRunFailedError extends Error {
162
185
  readonly id: WorkflowRunId;
163
186
  readonly attempts: number;
164
- readonly reason: string;
165
- readonly failureCause?: WorkflowFailureCause | undefined;
166
- constructor(id: WorkflowRunId, attempts: number, reason: string, failureCause?: WorkflowFailureCause | undefined);
167
- }
168
- declare class WorkflowRunSuspendedError extends Error {
169
- readonly id: WorkflowRunId;
170
- constructor(id: WorkflowRunId);
187
+ constructor(id: WorkflowRunId, attempts: number);
171
188
  }
172
189
 
173
- export { type NonTerminalWorkflowRunStatus, type TerminalWorkflowRunStatus, type WorkflowFailureCause, type WorkflowOptions, type WorkflowRun, WorkflowRunCancelledError, WorkflowRunConflictError, WorkflowRunFailedError, type WorkflowRunId, WorkflowRunNotExecutableError, WorkflowRunPausedError, type WorkflowRunScheduledReason, type WorkflowRunState, type WorkflowRunStateAwaitingBase, type WorkflowRunStateAwaitingChildWorkflow, type WorkflowRunStateAwaitingEvent, type WorkflowRunStateAwaitingRetry, type WorkflowRunStateAwaitingRetryCausedByChildWorkflow, type WorkflowRunStateAwaitingRetryCausedBySelf, type WorkflowRunStateAwaitingRetryCausedByTask, type WorkflowRunStateCancelled, type WorkflowRunStateCompleted, type WorkflowRunStateFailed, type WorkflowRunStateFailedByChildWorkflow, type WorkflowRunStateFailedBySelf, type WorkflowRunStateFailedByTask, type WorkflowRunStateInComplete, type WorkflowRunStatePaused, type WorkflowRunStateQueued, type WorkflowRunStateRunning, type WorkflowRunStateScheduled, type WorkflowRunStateScheduledByAwake, type WorkflowRunStateScheduledByEvent, type WorkflowRunStateScheduledByNew, type WorkflowRunStateScheduledByResume, type WorkflowRunStateScheduledByRetry, type WorkflowRunStateSleeping, type WorkflowRunStateTransition, type WorkflowRunStatus, WorkflowRunSuspendedError, type WorkflowRunTaskStateTransition, type WorkflowRunTransition, type WorkflowRunTransitionBase };
190
+ export { type ChildWorkflowRun, type ChildWorkflowWaitResult, type ChildWorkflowWaitResultCompleted, type ChildWorkflowWaitResultTimeout, type NonTerminalWorkflowRunStatus, type TerminalWorkflowRunStatus, type WorkflowFailureCause, type WorkflowOptions, type WorkflowRun, WorkflowRunFailedError, type WorkflowRunId, WorkflowRunNotExecutableError, type WorkflowRunPath, type WorkflowRunScheduledReason, type WorkflowRunState, type WorkflowRunStateAwaitingChildWorkflow, type WorkflowRunStateAwaitingEvent, type WorkflowRunStateAwaitingRetry, type WorkflowRunStateAwaitingRetryBase, type WorkflowRunStateAwaitingRetryCausedByChildWorkflow, type WorkflowRunStateAwaitingRetryCausedBySelf, type WorkflowRunStateAwaitingRetryCausedByTask, type WorkflowRunStateCancelled, type WorkflowRunStateCompleted, type WorkflowRunStateFailed, type WorkflowRunStateFailedByChildWorkflow, type WorkflowRunStateFailedBySelf, type WorkflowRunStateFailedByTask, type WorkflowRunStateInComplete, type WorkflowRunStatePaused, type WorkflowRunStateQueued, type WorkflowRunStateRunning, type WorkflowRunStateScheduled, type WorkflowRunStateScheduledByAwake, type WorkflowRunStateScheduledByChildWorkflow, type WorkflowRunStateScheduledByEvent, type WorkflowRunStateScheduledByNew, type WorkflowRunStateScheduledByResume, type WorkflowRunStateScheduledByRetry, type WorkflowRunStateScheduledByTaskRetry, type WorkflowRunStateSleeping, type WorkflowRunStateTransition, type WorkflowRunStatus, WorkflowRunSuspendedError, type WorkflowRunTaskStateTransition, type WorkflowRunTransition, type WorkflowRunTransitionBase, isTerminalWorkflowRunStatus };
@@ -1,13 +1,13 @@
1
1
  // workflow-run.ts
2
- var WorkflowRunConflictError = class extends Error {
3
- constructor(id, operation, attempts) {
4
- super(`Conflict while performing ${operation} on workflow ${id} after ${attempts} attempts`);
5
- this.id = id;
6
- this.operation = operation;
7
- this.attempts = attempts;
8
- this.name = "WorkflowRunConflictError";
2
+ var terminalWorkflowRunStatuses = ["cancelled", "completed", "failed"];
3
+ function isTerminalWorkflowRunStatus(status) {
4
+ for (const terminalStatus of terminalWorkflowRunStatuses) {
5
+ if (status === terminalStatus) {
6
+ return true;
7
+ }
9
8
  }
10
- };
9
+ return false;
10
+ }
11
11
  var WorkflowRunNotExecutableError = class extends Error {
12
12
  constructor(id, status) {
13
13
  super(`Workflow ${id} is not executable while ${status}`);
@@ -16,40 +16,24 @@ var WorkflowRunNotExecutableError = class extends Error {
16
16
  this.name = "WorkflowRunNotExecutableError";
17
17
  }
18
18
  };
19
- var WorkflowRunPausedError = class extends Error {
20
- constructor(id) {
21
- super(`Workflow ${id} paused`);
22
- this.name = "WorkflowRunPausedError";
23
- }
24
- };
25
- var WorkflowRunCancelledError = class extends Error {
19
+ var WorkflowRunSuspendedError = class extends Error {
26
20
  constructor(id) {
27
- super(`Workflow ${id} cancelled`);
28
- this.name = "WorkflowRunCancelledError";
21
+ super(`Workflow ${id} is suspended`);
22
+ this.id = id;
23
+ this.name = "WorkflowRunSuspendedError";
29
24
  }
30
25
  };
31
26
  var WorkflowRunFailedError = class extends Error {
32
- constructor(id, attempts, reason, failureCause) {
33
- super(`Workflow ${id} failed after ${attempts} attempt(s): ${reason}`);
27
+ constructor(id, attempts) {
28
+ super(`Workflow ${id} failed after ${attempts} attempt(s)`);
34
29
  this.id = id;
35
30
  this.attempts = attempts;
36
- this.reason = reason;
37
- this.failureCause = failureCause;
38
31
  this.name = "WorkflowRunFailedError";
39
32
  }
40
33
  };
41
- var WorkflowRunSuspendedError = class extends Error {
42
- constructor(id) {
43
- super(`Workflow ${id} is suspended`);
44
- this.id = id;
45
- this.name = "WorkflowRunSuspendedError";
46
- }
47
- };
48
34
  export {
49
- WorkflowRunCancelledError,
50
- WorkflowRunConflictError,
51
35
  WorkflowRunFailedError,
52
36
  WorkflowRunNotExecutableError,
53
- WorkflowRunPausedError,
54
- WorkflowRunSuspendedError
37
+ WorkflowRunSuspendedError,
38
+ isTerminalWorkflowRunStatus
55
39
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aikirun/types",
3
- "version": "0.5.3",
3
+ "version": "0.7.0",
4
4
  "description": "Core type definitions for Aiki - including workflow, task, client, and trigger types",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,6 +51,10 @@
51
51
  "./sleep": {
52
52
  "types": "./dist/sleep.d.ts",
53
53
  "import": "./dist/sleep.js"
54
+ },
55
+ "./event": {
56
+ "types": "./dist/event.d.ts",
57
+ "import": "./dist/event.js"
54
58
  }
55
59
  },
56
60
  "files": [