@aikirun/types 0.7.0 → 0.9.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/README.md +2 -0
- package/dist/client.d.ts +4 -4
- package/dist/duration.d.ts +2 -2
- package/dist/event.d.ts +8 -5
- package/dist/{error.d.ts → serializable.d.ts} +1 -1
- package/dist/sleep.d.ts +9 -17
- package/dist/task.d.ts +58 -10
- package/dist/task.js +3 -3
- package/dist/utils.d.ts +2 -2
- package/dist/validator.d.ts +5 -0
- package/dist/validator.js +0 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.js +0 -0
- package/dist/workflow-run-api.d.ts +42 -31
- package/dist/workflow-run.d.ts +36 -22
- package/dist/workflow-run.js +21 -4
- package/dist/workflow.d.ts +4 -4
- package/package.json +34 -26
- /package/dist/{error.js → serializable.js} +0 -0
package/README.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { WorkflowMeta } from './workflow.js';
|
|
|
2
2
|
import { WorkflowRun, WorkflowRunId } from './workflow-run.js';
|
|
3
3
|
import { WorkflowRunApi } from './workflow-run-api.js';
|
|
4
4
|
import { INTERNAL } from './symbols.js';
|
|
5
|
-
import './error.js';
|
|
6
5
|
import './event.js';
|
|
7
6
|
import './duration.js';
|
|
8
7
|
import './utils.js';
|
|
9
8
|
import './retry.js';
|
|
9
|
+
import './serializable.js';
|
|
10
10
|
import './sleep.js';
|
|
11
11
|
import './task.js';
|
|
12
12
|
import './trigger.js';
|
|
@@ -15,7 +15,7 @@ interface ClientParams<AppContext = unknown> {
|
|
|
15
15
|
url: string;
|
|
16
16
|
redis: RedisConfig;
|
|
17
17
|
logger?: Logger;
|
|
18
|
-
|
|
18
|
+
createContext?: (run: Readonly<WorkflowRun>) => AppContext | Promise<AppContext>;
|
|
19
19
|
}
|
|
20
20
|
interface Client<AppContext = unknown> {
|
|
21
21
|
api: ApiClient;
|
|
@@ -26,7 +26,7 @@ interface Client<AppContext = unknown> {
|
|
|
26
26
|
create: (strategy: SubscriberStrategy, workflows: WorkflowMeta[], workerShards?: string[]) => SubscriberStrategyBuilder;
|
|
27
27
|
};
|
|
28
28
|
redis: RedisConnection;
|
|
29
|
-
|
|
29
|
+
createContext?: (run: WorkflowRun) => AppContext | Promise<AppContext>;
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
interface Logger {
|
|
@@ -107,7 +107,7 @@ interface AdaptivePollingSubscriberStrategy {
|
|
|
107
107
|
atCapacityIntervalMs?: number;
|
|
108
108
|
}
|
|
109
109
|
interface RedisStreamsSubscriberStrategy {
|
|
110
|
-
type: "
|
|
110
|
+
type: "redis";
|
|
111
111
|
intervalMs?: number;
|
|
112
112
|
maxRetryIntervalMs?: number;
|
|
113
113
|
atCapacityIntervalMs?: number;
|
package/dist/duration.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequireAtLeastOneProp } from './utils.js';
|
|
2
2
|
|
|
3
3
|
interface DurationFields {
|
|
4
4
|
days?: number;
|
|
@@ -7,7 +7,7 @@ interface DurationFields {
|
|
|
7
7
|
seconds?: number;
|
|
8
8
|
milliseconds?: number;
|
|
9
9
|
}
|
|
10
|
-
type DurationObject =
|
|
10
|
+
type DurationObject = RequireAtLeastOneProp<DurationFields>;
|
|
11
11
|
type DurationMs = number;
|
|
12
12
|
type Duration = DurationMs | DurationObject;
|
|
13
13
|
|
package/dist/event.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DurationObject } from './duration.js';
|
|
2
2
|
import './utils.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
5
|
-
_brand: "
|
|
4
|
+
type EventName = string & {
|
|
5
|
+
_brand: "event_name";
|
|
6
6
|
};
|
|
7
7
|
type EventStatus = "received" | "timeout";
|
|
8
8
|
interface EventStateBase {
|
|
@@ -12,7 +12,7 @@ interface EventStateReceived<Data> extends EventStateBase {
|
|
|
12
12
|
status: "received";
|
|
13
13
|
data: Data;
|
|
14
14
|
receivedAt: number;
|
|
15
|
-
|
|
15
|
+
reference?: EventReferenceOptions;
|
|
16
16
|
}
|
|
17
17
|
interface EventStateTimeout extends EventStateBase {
|
|
18
18
|
status: "timeout";
|
|
@@ -34,7 +34,10 @@ type EventWaitState<Data, Timed extends boolean> = Timed extends false ? {
|
|
|
34
34
|
timeout: true;
|
|
35
35
|
};
|
|
36
36
|
interface EventSendOptions {
|
|
37
|
-
|
|
37
|
+
reference?: EventReferenceOptions;
|
|
38
|
+
}
|
|
39
|
+
interface EventReferenceOptions {
|
|
40
|
+
id: string;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
export type {
|
|
43
|
+
export type { EventName, EventQueue, EventReferenceOptions, EventSendOptions, EventState, EventStateReceived, EventStateTimeout, EventStatus, EventWaitOptions, EventWaitState };
|
package/dist/sleep.d.ts
CHANGED
|
@@ -1,37 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type SleepId = string & {
|
|
5
|
-
_brand: "sleep_id";
|
|
6
|
-
};
|
|
7
|
-
type SleepPath = string & {
|
|
8
|
-
_brand: "sleep_path";
|
|
1
|
+
type SleepName = string & {
|
|
2
|
+
_brand: "sleep_name";
|
|
9
3
|
};
|
|
10
|
-
type SleepStatus = "
|
|
4
|
+
type SleepStatus = "sleeping" | "completed" | "cancelled";
|
|
11
5
|
interface SleepStateBase {
|
|
12
6
|
status: SleepStatus;
|
|
13
7
|
}
|
|
14
|
-
interface SleepStateNone extends SleepStateBase {
|
|
15
|
-
status: "none";
|
|
16
|
-
}
|
|
17
8
|
interface SleepStateSleeping extends SleepStateBase {
|
|
18
9
|
status: "sleeping";
|
|
19
10
|
awakeAt: number;
|
|
20
11
|
}
|
|
21
12
|
interface SleepStateCompleted extends SleepStateBase {
|
|
22
13
|
status: "completed";
|
|
14
|
+
durationMs: number;
|
|
23
15
|
completedAt: number;
|
|
24
16
|
}
|
|
25
17
|
interface SleepStateCancelled extends SleepStateBase {
|
|
26
18
|
status: "cancelled";
|
|
27
19
|
cancelledAt: number;
|
|
28
20
|
}
|
|
29
|
-
type SleepState =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
21
|
+
type SleepState = SleepStateSleeping | SleepStateCompleted | SleepStateCancelled;
|
|
22
|
+
interface SleepQueue {
|
|
23
|
+
sleeps: SleepState[];
|
|
24
|
+
}
|
|
33
25
|
interface SleepResult {
|
|
34
26
|
cancelled: boolean;
|
|
35
27
|
}
|
|
36
28
|
|
|
37
|
-
export type {
|
|
29
|
+
export type { SleepName, SleepQueue, SleepResult, SleepState, SleepStateCancelled, SleepStateCompleted, SleepStateSleeping, SleepStatus };
|
package/dist/task.d.ts
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RetryStrategy } from './retry.js';
|
|
2
|
+
import { SerializableError } from './serializable.js';
|
|
2
3
|
|
|
3
4
|
type TaskId = string & {
|
|
4
5
|
_brand: "task_id";
|
|
5
6
|
};
|
|
7
|
+
type TaskName = string & {
|
|
8
|
+
_brand: "task_name";
|
|
9
|
+
};
|
|
6
10
|
type TaskPath = string & {
|
|
7
11
|
_brand: "task_path";
|
|
8
12
|
};
|
|
9
|
-
type TaskStatus = "
|
|
13
|
+
type TaskStatus = "running" | "awaiting_retry" | "completed" | "failed";
|
|
14
|
+
interface TaskOptions {
|
|
15
|
+
retry?: RetryStrategy;
|
|
16
|
+
reference?: TaskReferenceOptions;
|
|
17
|
+
}
|
|
18
|
+
interface TaskReferenceOptions {
|
|
19
|
+
id: string;
|
|
20
|
+
onConflict?: "error" | "return_existing";
|
|
21
|
+
}
|
|
10
22
|
interface TaskStateBase {
|
|
11
23
|
status: TaskStatus;
|
|
12
24
|
}
|
|
13
|
-
interface
|
|
14
|
-
status: "none";
|
|
15
|
-
}
|
|
16
|
-
interface TaskStateRunning extends TaskStateBase {
|
|
25
|
+
interface TaskStateRunning<Input> extends TaskStateBase {
|
|
17
26
|
status: "running";
|
|
18
27
|
attempts: number;
|
|
28
|
+
input: Input;
|
|
19
29
|
}
|
|
20
30
|
interface TaskStateAwaitingRetry extends TaskStateBase {
|
|
21
31
|
status: "awaiting_retry";
|
|
@@ -25,6 +35,7 @@ interface TaskStateAwaitingRetry extends TaskStateBase {
|
|
|
25
35
|
}
|
|
26
36
|
interface TaskStateCompleted<Output> extends TaskStateBase {
|
|
27
37
|
status: "completed";
|
|
38
|
+
attempts: number;
|
|
28
39
|
output: Output;
|
|
29
40
|
}
|
|
30
41
|
interface TaskStateFailed extends TaskStateBase {
|
|
@@ -32,12 +43,49 @@ interface TaskStateFailed extends TaskStateBase {
|
|
|
32
43
|
attempts: number;
|
|
33
44
|
error: SerializableError;
|
|
34
45
|
}
|
|
35
|
-
type TaskState<Output = unknown> =
|
|
46
|
+
type TaskState<Input = unknown, Output = unknown> = TaskStateRunning<Input> | TaskStateAwaitingRetry | TaskStateCompleted<Output> | TaskStateFailed;
|
|
47
|
+
interface TaskInfo {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
state: TaskState;
|
|
51
|
+
inputHash: string;
|
|
52
|
+
}
|
|
53
|
+
interface TransitionTaskStateBase {
|
|
54
|
+
id: string;
|
|
55
|
+
expectedRevision: number;
|
|
56
|
+
}
|
|
57
|
+
interface TransitionTaskStateToRunningCreate extends TransitionTaskStateBase {
|
|
58
|
+
type: "create";
|
|
59
|
+
taskName: string;
|
|
60
|
+
options?: TaskOptions;
|
|
61
|
+
taskState: TaskStateRunning<unknown>;
|
|
62
|
+
}
|
|
63
|
+
interface TransitionTaskStateToRunningRetry extends TransitionTaskStateBase {
|
|
64
|
+
type: "retry";
|
|
65
|
+
taskId: string;
|
|
66
|
+
options?: TaskOptions;
|
|
67
|
+
taskState: TaskStateRunning<unknown>;
|
|
68
|
+
}
|
|
69
|
+
interface TransitionTaskStateToCompleted extends TransitionTaskStateBase {
|
|
70
|
+
taskId: string;
|
|
71
|
+
taskState: TaskStateCompleted<unknown>;
|
|
72
|
+
}
|
|
73
|
+
interface TransitionTaskStateToFailed extends TransitionTaskStateBase {
|
|
74
|
+
taskId: string;
|
|
75
|
+
taskState: TaskStateFailed;
|
|
76
|
+
}
|
|
77
|
+
interface TransitionTaskStateToAwaitingRetry extends TransitionTaskStateBase {
|
|
78
|
+
taskId: string;
|
|
79
|
+
taskState: TaskStateAwaitingRetryRequest;
|
|
80
|
+
}
|
|
81
|
+
type TaskStateAwaitingRetryRequest = Omit<TaskStateAwaitingRetry, "nextAttemptAt"> & {
|
|
82
|
+
nextAttemptInMs: number;
|
|
83
|
+
};
|
|
36
84
|
declare class TaskFailedError extends Error {
|
|
37
|
-
readonly
|
|
85
|
+
readonly taskId: TaskId;
|
|
38
86
|
readonly attempts: number;
|
|
39
87
|
readonly reason: string;
|
|
40
|
-
constructor(
|
|
88
|
+
constructor(taskId: TaskId, attempts: number, reason: string);
|
|
41
89
|
}
|
|
42
90
|
|
|
43
|
-
export { TaskFailedError, type TaskId, type TaskPath, type TaskState, type TaskStateAwaitingRetry, type
|
|
91
|
+
export { TaskFailedError, type TaskId, type TaskInfo, type TaskName, type TaskOptions, type TaskPath, type TaskReferenceOptions, type TaskState, type TaskStateAwaitingRetry, type TaskStateAwaitingRetryRequest, type TaskStateCompleted, type TaskStateFailed, type TaskStateRunning, type TaskStatus, type TransitionTaskStateBase, type TransitionTaskStateToAwaitingRetry, type TransitionTaskStateToCompleted, type TransitionTaskStateToFailed, type TransitionTaskStateToRunningCreate, type TransitionTaskStateToRunningRetry };
|
package/dist/task.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// task.ts
|
|
2
2
|
var TaskFailedError = class extends Error {
|
|
3
|
-
constructor(
|
|
4
|
-
super(`Task ${
|
|
5
|
-
this.
|
|
3
|
+
constructor(taskId, attempts, reason) {
|
|
4
|
+
super(`Task ${taskId} failed after ${attempts} attempts. Reason: ${reason}`);
|
|
5
|
+
this.taskId = taskId;
|
|
6
6
|
this.attempts = attempts;
|
|
7
7
|
this.reason = reason;
|
|
8
8
|
this.name = "TaskFailedError";
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
type
|
|
1
|
+
type RequireAtLeastOneProp<T, Keys extends keyof T = keyof T> = {
|
|
2
2
|
[K in Keys]-?: Required<Pick<T, K>> & Omit<T, K>;
|
|
3
3
|
}[Keys];
|
|
4
4
|
type DistributiveOmit<T, K extends keyof T> = T extends T ? Omit<T, K> : never;
|
|
5
5
|
|
|
6
|
-
export type { DistributiveOmit,
|
|
6
|
+
export type { DistributiveOmit, RequireAtLeastOneProp };
|
|
File without changes
|
package/dist/worker.d.ts
ADDED
package/dist/worker.js
ADDED
|
File without changes
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { EventSendOptions } from './event.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TransitionTaskStateToRunningCreate, TransitionTaskStateToRunningRetry, TransitionTaskStateToCompleted, TransitionTaskStateToFailed, TransitionTaskStateToAwaitingRetry, TaskStateCompleted, TaskStateFailed } from './task.js';
|
|
3
3
|
import { DistributiveOmit } from './utils.js';
|
|
4
4
|
import { WorkflowRunStatus, WorkflowRun, WorkflowRunState, WorkflowOptions, WorkflowRunStateScheduled, WorkflowRunStateAwaitingEvent, WorkflowRunStateAwaitingRetry, WorkflowRunStateAwaitingChildWorkflow, WorkflowRunStatePaused, WorkflowRunStateCancelled, WorkflowRunTransition } from './workflow-run.js';
|
|
5
5
|
import './duration.js';
|
|
6
|
-
import './error.js';
|
|
7
6
|
import './retry.js';
|
|
7
|
+
import './serializable.js';
|
|
8
8
|
import './sleep.js';
|
|
9
9
|
import './trigger.js';
|
|
10
10
|
|
|
11
11
|
interface WorkflowRunApi {
|
|
12
|
-
listV1: (
|
|
13
|
-
getByIdV1: (
|
|
14
|
-
getStateV1: (
|
|
15
|
-
createV1: (
|
|
16
|
-
transitionStateV1: (
|
|
17
|
-
transitionTaskStateV1: (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
listV1: (_: WorkflowRunListRequestV1) => Promise<WorkflowRunListResponseV1>;
|
|
13
|
+
getByIdV1: (_: WorkflowRunGetByIdRequestV1) => Promise<WorkflowRunGetByIdResponseV1>;
|
|
14
|
+
getStateV1: (_: WorkflowRunGetStateRequestV1) => Promise<WorkflowRunGetStateResponseV1>;
|
|
15
|
+
createV1: (_: WorkflowRunCreateRequestV1) => Promise<WorkflowRunCreateResponseV1>;
|
|
16
|
+
transitionStateV1: (_: WorkflowRunTransitionStateRequestV1) => Promise<WorkflowRunTransitionStateResponseV1>;
|
|
17
|
+
transitionTaskStateV1: (_: WorkflowRunTransitionTaskStateRequestV1) => Promise<WorkflowRunTransitionTaskStateResponseV1>;
|
|
18
|
+
setTaskStateV1: (_: WorkflowRunSetTaskStateRequestV1) => Promise<WorkflowRunSetTaskStateResponseV1>;
|
|
19
|
+
listTransitionsV1: (_: WorkflowRunListTransitionsRequestV1) => Promise<WorkflowRunListTransitionsResponseV1>;
|
|
20
|
+
sendEventV1: (_: WorkflowRunSendEventRequestV1) => Promise<WorkflowRunSendEventResponseV1>;
|
|
21
|
+
multicastEventV1: (_: WorkflowRunMulticastEventRequestV1) => Promise<void>;
|
|
21
22
|
}
|
|
22
23
|
interface WorkflowRunListRequestV1 {
|
|
23
24
|
limit?: number;
|
|
@@ -36,8 +37,8 @@ interface WorkflowRunListRequestV1 {
|
|
|
36
37
|
}
|
|
37
38
|
interface WorkflowRunListItem {
|
|
38
39
|
id: string;
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
name: string;
|
|
41
|
+
versionId: string;
|
|
41
42
|
createdAt: number;
|
|
42
43
|
status: WorkflowRunStatus;
|
|
43
44
|
}
|
|
@@ -58,10 +59,9 @@ interface WorkflowRunGetStateResponseV1 {
|
|
|
58
59
|
state: WorkflowRunState;
|
|
59
60
|
}
|
|
60
61
|
interface WorkflowRunCreateRequestV1 {
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
name: string;
|
|
63
|
+
versionId: string;
|
|
63
64
|
input: unknown;
|
|
64
|
-
path?: string;
|
|
65
65
|
parentWorkflowRunId?: string;
|
|
66
66
|
options?: WorkflowOptions;
|
|
67
67
|
}
|
|
@@ -89,7 +89,7 @@ interface WorkflowRunTransitionStateRequestBase {
|
|
|
89
89
|
state: WorkflowRunStateRequest;
|
|
90
90
|
}
|
|
91
91
|
type WorkflowRunStateScheduledRequestOptimistic = Extract<WorkflowRunStateScheduledRequest, {
|
|
92
|
-
reason: "retry" | "task_retry" | "event" | "child_workflow";
|
|
92
|
+
reason: "retry" | "task_retry" | "awake" | "event" | "child_workflow";
|
|
93
93
|
}>;
|
|
94
94
|
type WorkflowRunStateScheduledRequestPessimistic = Exclude<WorkflowRunStateScheduledRequest, WorkflowRunStateScheduledRequestOptimistic>;
|
|
95
95
|
interface WorkflowRunTransitionStateRequestOptimistic extends WorkflowRunTransitionStateRequestBase {
|
|
@@ -107,19 +107,30 @@ type WorkflowRunTransitionStateRequestV1 = WorkflowRunTransitionStateRequestOpti
|
|
|
107
107
|
interface WorkflowRunTransitionStateResponseV1 {
|
|
108
108
|
run: WorkflowRun;
|
|
109
109
|
}
|
|
110
|
-
type
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
interface
|
|
110
|
+
type TransitionTaskStateToRunning = TransitionTaskStateToRunningCreate | TransitionTaskStateToRunningRetry;
|
|
111
|
+
type WorkflowRunTransitionTaskStateRequestV1 = TransitionTaskStateToRunning | TransitionTaskStateToCompleted | TransitionTaskStateToFailed | TransitionTaskStateToAwaitingRetry;
|
|
112
|
+
interface WorkflowRunTransitionTaskStateResponseV1 {
|
|
113
|
+
run: WorkflowRun;
|
|
114
|
+
taskId: string;
|
|
115
|
+
}
|
|
116
|
+
interface WorkflowRunSetTaskStateRequestNew {
|
|
117
|
+
type: "new";
|
|
117
118
|
id: string;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
taskName: string;
|
|
120
|
+
input: unknown;
|
|
121
|
+
reference?: {
|
|
122
|
+
id: string;
|
|
123
|
+
};
|
|
124
|
+
state: DistributiveOmit<TaskStateCompleted<unknown> | TaskStateFailed, "attempts">;
|
|
121
125
|
}
|
|
122
|
-
interface
|
|
126
|
+
interface WorkflowRunSetTaskStateRequestExisting {
|
|
127
|
+
type: "existing";
|
|
128
|
+
id: string;
|
|
129
|
+
taskId: string;
|
|
130
|
+
state: DistributiveOmit<TaskStateCompleted<unknown> | TaskStateFailed, "attempts">;
|
|
131
|
+
}
|
|
132
|
+
type WorkflowRunSetTaskStateRequestV1 = WorkflowRunSetTaskStateRequestNew | WorkflowRunSetTaskStateRequestExisting;
|
|
133
|
+
interface WorkflowRunSetTaskStateResponseV1 {
|
|
123
134
|
run: WorkflowRun;
|
|
124
135
|
}
|
|
125
136
|
interface WorkflowRunListTransitionsRequestV1 {
|
|
@@ -137,7 +148,7 @@ interface WorkflowRunListTransitionsResponseV1 {
|
|
|
137
148
|
}
|
|
138
149
|
interface WorkflowRunSendEventRequestV1 {
|
|
139
150
|
id: string;
|
|
140
|
-
|
|
151
|
+
eventName: string;
|
|
141
152
|
data: unknown;
|
|
142
153
|
options?: EventSendOptions;
|
|
143
154
|
}
|
|
@@ -146,9 +157,9 @@ interface WorkflowRunSendEventResponseV1 {
|
|
|
146
157
|
}
|
|
147
158
|
interface WorkflowRunMulticastEventRequestV1 {
|
|
148
159
|
ids: string[];
|
|
149
|
-
|
|
160
|
+
eventName: string;
|
|
150
161
|
data: unknown;
|
|
151
162
|
options?: EventSendOptions;
|
|
152
163
|
}
|
|
153
164
|
|
|
154
|
-
export type {
|
|
165
|
+
export type { TransitionTaskStateToRunning, WorkflowRunApi, WorkflowRunCreateRequestV1, WorkflowRunCreateResponseV1, WorkflowRunGetByIdRequestV1, WorkflowRunGetByIdResponseV1, WorkflowRunGetStateRequestV1, WorkflowRunGetStateResponseV1, WorkflowRunListItem, WorkflowRunListRequestV1, WorkflowRunListResponseV1, WorkflowRunListTransitionsRequestV1, WorkflowRunListTransitionsResponseV1, WorkflowRunMulticastEventRequestV1, WorkflowRunSendEventRequestV1, WorkflowRunSendEventResponseV1, WorkflowRunSetTaskStateRequestExisting, WorkflowRunSetTaskStateRequestNew, WorkflowRunSetTaskStateRequestV1, WorkflowRunSetTaskStateResponseV1, WorkflowRunStateAwaitingChildWorkflowRequest, WorkflowRunStateAwaitingEventRequest, WorkflowRunStateAwaitingRetryRequest, WorkflowRunStateRequest, WorkflowRunStateScheduledRequest, WorkflowRunStateScheduledRequestOptimistic, WorkflowRunStateScheduledRequestPessimistic, WorkflowRunTransitionStateRequestOptimistic, WorkflowRunTransitionStateRequestPessimistic, WorkflowRunTransitionStateRequestV1, WorkflowRunTransitionStateResponseV1, WorkflowRunTransitionTaskStateRequestV1, WorkflowRunTransitionTaskStateResponseV1 };
|
package/dist/workflow-run.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SerializableError } from './error.js';
|
|
2
1
|
import { EventQueue } from './event.js';
|
|
3
2
|
import { RetryStrategy } from './retry.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { SerializableError } from './serializable.js';
|
|
4
|
+
import { SleepQueue } from './sleep.js';
|
|
5
|
+
import { TaskInfo, TaskState } from './task.js';
|
|
6
6
|
import { TriggerStrategy } from './trigger.js';
|
|
7
7
|
import './duration.js';
|
|
8
8
|
import './utils.js';
|
|
@@ -18,16 +18,20 @@ declare const terminalWorkflowRunStatuses: readonly ["cancelled", "completed", "
|
|
|
18
18
|
type TerminalWorkflowRunStatus = (typeof terminalWorkflowRunStatuses)[number];
|
|
19
19
|
type NonTerminalWorkflowRunStatus = Exclude<WorkflowRunStatus, TerminalWorkflowRunStatus>;
|
|
20
20
|
declare function isTerminalWorkflowRunStatus(status: WorkflowRunStatus): status is TerminalWorkflowRunStatus;
|
|
21
|
+
interface WorkflowReferenceOptions {
|
|
22
|
+
id: string;
|
|
23
|
+
onConflict?: "error" | "return_existing";
|
|
24
|
+
}
|
|
21
25
|
interface WorkflowOptions {
|
|
22
26
|
retry?: RetryStrategy;
|
|
23
|
-
|
|
27
|
+
reference?: WorkflowReferenceOptions;
|
|
24
28
|
trigger?: TriggerStrategy;
|
|
25
|
-
|
|
29
|
+
shard?: string;
|
|
26
30
|
}
|
|
27
31
|
interface WorkflowRunStateBase {
|
|
28
32
|
status: WorkflowRunStatus;
|
|
29
33
|
}
|
|
30
|
-
type WorkflowRunScheduledReason = "new" | "retry" | "task_retry" | "awake" | "resume" | "event" | "child_workflow";
|
|
34
|
+
type WorkflowRunScheduledReason = "new" | "retry" | "task_retry" | "awake" | "awake_early" | "resume" | "event" | "child_workflow";
|
|
31
35
|
interface WorkflowRunStateScheduledBase extends WorkflowRunStateBase {
|
|
32
36
|
status: "scheduled";
|
|
33
37
|
scheduledAt: number;
|
|
@@ -45,6 +49,9 @@ interface WorkflowRunStateScheduledByTaskRetry extends WorkflowRunStateScheduled
|
|
|
45
49
|
interface WorkflowRunStateScheduledByAwake extends WorkflowRunStateScheduledBase {
|
|
46
50
|
reason: "awake";
|
|
47
51
|
}
|
|
52
|
+
interface WorkflowRunStateScheduledByAwakeEarly extends WorkflowRunStateScheduledBase {
|
|
53
|
+
reason: "awake_early";
|
|
54
|
+
}
|
|
48
55
|
interface WorkflowRunStateScheduledByResume extends WorkflowRunStateScheduledBase {
|
|
49
56
|
reason: "resume";
|
|
50
57
|
}
|
|
@@ -54,7 +61,7 @@ interface WorkflowRunStateScheduledByEvent extends WorkflowRunStateScheduledBase
|
|
|
54
61
|
interface WorkflowRunStateScheduledByChildWorkflow extends WorkflowRunStateScheduledBase {
|
|
55
62
|
reason: "child_workflow";
|
|
56
63
|
}
|
|
57
|
-
type WorkflowRunStateScheduled = WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByRetry | WorkflowRunStateScheduledByTaskRetry | WorkflowRunStateScheduledByAwake | WorkflowRunStateScheduledByResume | WorkflowRunStateScheduledByEvent | WorkflowRunStateScheduledByChildWorkflow;
|
|
64
|
+
type WorkflowRunStateScheduled = WorkflowRunStateScheduledByNew | WorkflowRunStateScheduledByRetry | WorkflowRunStateScheduledByTaskRetry | WorkflowRunStateScheduledByAwake | WorkflowRunStateScheduledByAwakeEarly | WorkflowRunStateScheduledByResume | WorkflowRunStateScheduledByEvent | WorkflowRunStateScheduledByChildWorkflow;
|
|
58
65
|
interface WorkflowRunStateQueued extends WorkflowRunStateBase {
|
|
59
66
|
status: "queued";
|
|
60
67
|
reason: WorkflowRunScheduledReason;
|
|
@@ -67,12 +74,12 @@ interface WorkflowRunStatePaused extends WorkflowRunStateBase {
|
|
|
67
74
|
}
|
|
68
75
|
interface WorkflowRunStateSleeping extends WorkflowRunStateBase {
|
|
69
76
|
status: "sleeping";
|
|
70
|
-
|
|
77
|
+
sleepName: string;
|
|
71
78
|
durationMs: number;
|
|
72
79
|
}
|
|
73
80
|
interface WorkflowRunStateAwaitingEvent extends WorkflowRunStateBase {
|
|
74
81
|
status: "awaiting_event";
|
|
75
|
-
|
|
82
|
+
eventName: string;
|
|
76
83
|
timeoutAt?: number;
|
|
77
84
|
}
|
|
78
85
|
type WorkflowFailureCause = "task" | "child_workflow" | "self";
|
|
@@ -83,7 +90,7 @@ interface WorkflowRunStateAwaitingRetryBase extends WorkflowRunStateBase {
|
|
|
83
90
|
}
|
|
84
91
|
interface WorkflowRunStateAwaitingRetryCausedByTask extends WorkflowRunStateAwaitingRetryBase {
|
|
85
92
|
cause: "task";
|
|
86
|
-
|
|
93
|
+
taskId: string;
|
|
87
94
|
}
|
|
88
95
|
interface WorkflowRunStateAwaitingRetryCausedByChildWorkflow extends WorkflowRunStateAwaitingRetryBase {
|
|
89
96
|
cause: "child_workflow";
|
|
@@ -96,7 +103,7 @@ interface WorkflowRunStateAwaitingRetryCausedBySelf extends WorkflowRunStateAwai
|
|
|
96
103
|
type WorkflowRunStateAwaitingRetry = WorkflowRunStateAwaitingRetryCausedByTask | WorkflowRunStateAwaitingRetryCausedByChildWorkflow | WorkflowRunStateAwaitingRetryCausedBySelf;
|
|
97
104
|
interface WorkflowRunStateAwaitingChildWorkflow extends WorkflowRunStateBase {
|
|
98
105
|
status: "awaiting_child_workflow";
|
|
99
|
-
|
|
106
|
+
childWorkflowRunId: string;
|
|
100
107
|
childWorkflowRunStatus: WorkflowRunStatus;
|
|
101
108
|
timeoutAt?: number;
|
|
102
109
|
}
|
|
@@ -114,7 +121,7 @@ interface WorkflowRunStateFailedBase extends WorkflowRunStateBase {
|
|
|
114
121
|
}
|
|
115
122
|
interface WorkflowRunStateFailedByTask extends WorkflowRunStateFailedBase {
|
|
116
123
|
cause: "task";
|
|
117
|
-
|
|
124
|
+
taskId: string;
|
|
118
125
|
}
|
|
119
126
|
interface WorkflowRunStateFailedByChildWorkflow extends WorkflowRunStateFailedBase {
|
|
120
127
|
cause: "child_workflow";
|
|
@@ -129,23 +136,24 @@ type WorkflowRunStateInComplete = WorkflowRunStateScheduled | WorkflowRunStateQu
|
|
|
129
136
|
type WorkflowRunState<Output = unknown> = WorkflowRunStateInComplete | WorkflowRunStateCompleted<Output>;
|
|
130
137
|
interface WorkflowRun<Input = unknown, Output = unknown> {
|
|
131
138
|
id: string;
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
name: string;
|
|
140
|
+
versionId: string;
|
|
134
141
|
createdAt: number;
|
|
135
142
|
revision: number;
|
|
136
143
|
input: Input;
|
|
137
|
-
path
|
|
144
|
+
path: string;
|
|
138
145
|
options: WorkflowOptions;
|
|
139
146
|
attempts: number;
|
|
140
147
|
state: WorkflowRunState<Output>;
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
tasks: Record<string, TaskInfo>;
|
|
149
|
+
sleepsQueue: Record<string, SleepQueue>;
|
|
143
150
|
eventsQueue: Record<string, EventQueue<unknown>>;
|
|
144
|
-
childWorkflowRuns: Record<string,
|
|
151
|
+
childWorkflowRuns: Record<string, ChildWorkflowRunInfo>;
|
|
145
152
|
parentWorkflowRunId?: string;
|
|
146
153
|
}
|
|
147
|
-
interface
|
|
154
|
+
interface ChildWorkflowRunInfo {
|
|
148
155
|
id: string;
|
|
156
|
+
inputHash: string;
|
|
149
157
|
statusWaitResults: ChildWorkflowWaitResult[];
|
|
150
158
|
}
|
|
151
159
|
type ChildWorkflowWaitResult = ChildWorkflowWaitResultCompleted | ChildWorkflowWaitResultTimeout;
|
|
@@ -159,6 +167,7 @@ interface ChildWorkflowWaitResultTimeout {
|
|
|
159
167
|
timedOutAt: number;
|
|
160
168
|
}
|
|
161
169
|
interface WorkflowRunTransitionBase {
|
|
170
|
+
id: string;
|
|
162
171
|
createdAt: number;
|
|
163
172
|
type: "state" | "task_state";
|
|
164
173
|
}
|
|
@@ -168,7 +177,7 @@ interface WorkflowRunStateTransition extends WorkflowRunTransitionBase {
|
|
|
168
177
|
}
|
|
169
178
|
interface WorkflowRunTaskStateTransition extends WorkflowRunTransitionBase {
|
|
170
179
|
type: "task_state";
|
|
171
|
-
|
|
180
|
+
taskId: string;
|
|
172
181
|
taskState: TaskState;
|
|
173
182
|
}
|
|
174
183
|
type WorkflowRunTransition = WorkflowRunStateTransition | WorkflowRunTaskStateTransition;
|
|
@@ -184,7 +193,12 @@ declare class WorkflowRunSuspendedError extends Error {
|
|
|
184
193
|
declare class WorkflowRunFailedError extends Error {
|
|
185
194
|
readonly id: WorkflowRunId;
|
|
186
195
|
readonly attempts: number;
|
|
187
|
-
|
|
196
|
+
readonly reason?: string | undefined;
|
|
197
|
+
constructor(id: WorkflowRunId, attempts: number, reason?: string | undefined);
|
|
198
|
+
}
|
|
199
|
+
declare class WorkflowRunConflictError extends Error {
|
|
200
|
+
readonly id: WorkflowRunId;
|
|
201
|
+
constructor(id: WorkflowRunId);
|
|
188
202
|
}
|
|
189
203
|
|
|
190
|
-
export { type
|
|
204
|
+
export { type ChildWorkflowRunInfo, type ChildWorkflowWaitResult, type ChildWorkflowWaitResultCompleted, type ChildWorkflowWaitResultTimeout, type NonTerminalWorkflowRunStatus, type TerminalWorkflowRunStatus, type WorkflowFailureCause, type WorkflowOptions, type WorkflowReferenceOptions, type WorkflowRun, WorkflowRunConflictError, 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 WorkflowRunStateScheduledByAwakeEarly, 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 };
|
package/dist/workflow-run.js
CHANGED
|
@@ -24,14 +24,31 @@ var WorkflowRunSuspendedError = class extends Error {
|
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
var WorkflowRunFailedError = class extends Error {
|
|
27
|
-
constructor(id, attempts) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
constructor(id, attempts, reason) {
|
|
28
|
+
var __super = (...args) => {
|
|
29
|
+
super(...args);
|
|
30
|
+
this.id = id;
|
|
31
|
+
this.attempts = attempts;
|
|
32
|
+
this.reason = reason;
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
if (reason) {
|
|
36
|
+
__super(`Workflow ${id} failed after ${attempts} attempt(s): ${reason}`);
|
|
37
|
+
} else {
|
|
38
|
+
__super(`Workflow ${id} failed after ${attempts} attempt(s)`);
|
|
39
|
+
}
|
|
31
40
|
this.name = "WorkflowRunFailedError";
|
|
32
41
|
}
|
|
33
42
|
};
|
|
43
|
+
var WorkflowRunConflictError = class extends Error {
|
|
44
|
+
constructor(id) {
|
|
45
|
+
super(`Conflict while trying to update Workflow run ${id}`);
|
|
46
|
+
this.id = id;
|
|
47
|
+
this.name = "WorkflowRunConflictError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
34
50
|
export {
|
|
51
|
+
WorkflowRunConflictError,
|
|
35
52
|
WorkflowRunFailedError,
|
|
36
53
|
WorkflowRunNotExecutableError,
|
|
37
54
|
WorkflowRunSuspendedError,
|
package/dist/workflow.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
type
|
|
2
|
-
_brand: "
|
|
1
|
+
type WorkflowName = string & {
|
|
2
|
+
_brand: "workflow_name";
|
|
3
3
|
};
|
|
4
4
|
type WorkflowVersionId = string & {
|
|
5
5
|
_brand: "workflow_version_id";
|
|
6
6
|
};
|
|
7
7
|
interface WorkflowMeta {
|
|
8
|
-
|
|
8
|
+
name: WorkflowName;
|
|
9
9
|
versionId: WorkflowVersionId;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export type {
|
|
12
|
+
export type { WorkflowMeta, WorkflowName, WorkflowVersionId };
|
package/package.json
CHANGED
|
@@ -1,37 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aikirun/types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Core type definitions for Aiki - including workflow, task, client, and trigger types",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
-
"./
|
|
8
|
-
"types": "./dist/
|
|
9
|
-
"import": "./dist/
|
|
10
|
-
},
|
|
11
|
-
"./symbols": {
|
|
12
|
-
"types": "./dist/symbols.d.ts",
|
|
13
|
-
"import": "./dist/symbols.js"
|
|
7
|
+
"./client": {
|
|
8
|
+
"types": "./dist/client.d.ts",
|
|
9
|
+
"import": "./dist/client.js"
|
|
14
10
|
},
|
|
15
11
|
"./duration": {
|
|
16
12
|
"types": "./dist/duration.d.ts",
|
|
17
13
|
"import": "./dist/duration.js"
|
|
18
14
|
},
|
|
15
|
+
"./event": {
|
|
16
|
+
"types": "./dist/event.d.ts",
|
|
17
|
+
"import": "./dist/event.js"
|
|
18
|
+
},
|
|
19
19
|
"./retry": {
|
|
20
20
|
"types": "./dist/retry.d.ts",
|
|
21
21
|
"import": "./dist/retry.js"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"types": "./dist/
|
|
25
|
-
"import": "./dist/
|
|
23
|
+
"./serializable": {
|
|
24
|
+
"types": "./dist/serializable.d.ts",
|
|
25
|
+
"import": "./dist/serializable.js"
|
|
26
26
|
},
|
|
27
|
-
"./
|
|
28
|
-
"types": "./dist/
|
|
29
|
-
"import": "./dist/
|
|
27
|
+
"./sleep": {
|
|
28
|
+
"types": "./dist/sleep.d.ts",
|
|
29
|
+
"import": "./dist/sleep.js"
|
|
30
|
+
},
|
|
31
|
+
"./symbols": {
|
|
32
|
+
"types": "./dist/symbols.d.ts",
|
|
33
|
+
"import": "./dist/symbols.js"
|
|
34
|
+
},
|
|
35
|
+
"./task": {
|
|
36
|
+
"types": "./dist/task.d.ts",
|
|
37
|
+
"import": "./dist/task.js"
|
|
30
38
|
},
|
|
31
39
|
"./trigger": {
|
|
32
40
|
"types": "./dist/trigger.d.ts",
|
|
33
41
|
"import": "./dist/trigger.js"
|
|
34
42
|
},
|
|
43
|
+
"./utils": {
|
|
44
|
+
"types": "./dist/utils.d.ts",
|
|
45
|
+
"import": "./dist/utils.js"
|
|
46
|
+
},
|
|
47
|
+
"./validator": {
|
|
48
|
+
"types": "./dist/validator.d.ts",
|
|
49
|
+
"import": "./dist/validator.js"
|
|
50
|
+
},
|
|
51
|
+
"./worker": {
|
|
52
|
+
"types": "./dist/worker.d.ts",
|
|
53
|
+
"import": "./dist/worker.js"
|
|
54
|
+
},
|
|
35
55
|
"./workflow": {
|
|
36
56
|
"types": "./dist/workflow.d.ts",
|
|
37
57
|
"import": "./dist/workflow.js"
|
|
@@ -43,18 +63,6 @@
|
|
|
43
63
|
"./workflow-run-api": {
|
|
44
64
|
"types": "./dist/workflow-run-api.d.ts",
|
|
45
65
|
"import": "./dist/workflow-run-api.js"
|
|
46
|
-
},
|
|
47
|
-
"./task": {
|
|
48
|
-
"types": "./dist/task.d.ts",
|
|
49
|
-
"import": "./dist/task.js"
|
|
50
|
-
},
|
|
51
|
-
"./sleep": {
|
|
52
|
-
"types": "./dist/sleep.d.ts",
|
|
53
|
-
"import": "./dist/sleep.js"
|
|
54
|
-
},
|
|
55
|
-
"./event": {
|
|
56
|
-
"types": "./dist/event.d.ts",
|
|
57
|
-
"import": "./dist/event.js"
|
|
58
66
|
}
|
|
59
67
|
},
|
|
60
68
|
"files": [
|
|
File without changes
|