@tanstack/workflow-runtime 0.0.1
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 +22 -0
- package/dist/define-runtime.cjs +50 -0
- package/dist/define-runtime.cjs.map +1 -0
- package/dist/define-runtime.d.cts +16 -0
- package/dist/define-runtime.d.ts +16 -0
- package/dist/define-runtime.js +48 -0
- package/dist/define-runtime.js.map +1 -0
- package/dist/in-memory-store.cjs +457 -0
- package/dist/in-memory-store.cjs.map +1 -0
- package/dist/in-memory-store.d.cts +8 -0
- package/dist/in-memory-store.d.ts +8 -0
- package/dist/in-memory-store.js +457 -0
- package/dist/in-memory-store.js.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/run-store-adapter.cjs +30 -0
- package/dist/run-store-adapter.cjs.map +1 -0
- package/dist/run-store-adapter.d.cts +7 -0
- package/dist/run-store-adapter.d.ts +7 -0
- package/dist/run-store-adapter.js +29 -0
- package/dist/run-store-adapter.js.map +1 -0
- package/dist/runtime-driver.cjs +334 -0
- package/dist/runtime-driver.cjs.map +1 -0
- package/dist/runtime-driver.d.cts +12 -0
- package/dist/runtime-driver.d.ts +12 -0
- package/dist/runtime-driver.js +334 -0
- package/dist/runtime-driver.js.map +1 -0
- package/dist/schedule-materializer.cjs +156 -0
- package/dist/schedule-materializer.cjs.map +1 -0
- package/dist/schedule-materializer.d.cts +28 -0
- package/dist/schedule-materializer.d.ts +28 -0
- package/dist/schedule-materializer.js +155 -0
- package/dist/schedule-materializer.js.map +1 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +375 -0
- package/dist/types.d.ts +375 -0
- package/dist/types.js +1 -0
- package/package.json +60 -0
- package/src/define-runtime.ts +46 -0
- package/src/in-memory-store.ts +607 -0
- package/src/index.ts +74 -0
- package/src/run-store-adapter.ts +49 -0
- package/src/runtime-driver.ts +536 -0
- package/src/schedule-materializer.ts +272 -0
- package/src/types.ts +462 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { AnyWorkflowDefinition, ApprovalResult, DeleteReason, RunState, RunStatus, RunStore, SerializedError, SignalDelivery, WorkflowEvent } from "@tanstack/workflow-core";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type WorkflowId = string;
|
|
5
|
+
type WorkflowVersion = string;
|
|
6
|
+
type RunId = string;
|
|
7
|
+
type ScheduleId = string;
|
|
8
|
+
type ScheduleBucketId = string;
|
|
9
|
+
type LeaseOwner = string;
|
|
10
|
+
type WorkflowExecutionStatus = RunStatus | 'queued';
|
|
11
|
+
interface WorkflowLease {
|
|
12
|
+
owner: LeaseOwner;
|
|
13
|
+
expiresAt: number;
|
|
14
|
+
}
|
|
15
|
+
interface WorkflowExecution {
|
|
16
|
+
runId: RunId;
|
|
17
|
+
workflowId: WorkflowId;
|
|
18
|
+
workflowVersion?: WorkflowVersion;
|
|
19
|
+
status: WorkflowExecutionStatus;
|
|
20
|
+
input: unknown;
|
|
21
|
+
output?: unknown;
|
|
22
|
+
error?: SerializedError;
|
|
23
|
+
waitingFor?: RunState['waitingFor'];
|
|
24
|
+
pendingApproval?: RunState['pendingApproval'];
|
|
25
|
+
wakeAt?: number;
|
|
26
|
+
lease?: WorkflowLease;
|
|
27
|
+
createdAt: number;
|
|
28
|
+
updatedAt: number;
|
|
29
|
+
}
|
|
30
|
+
interface StoredWorkflowEvent {
|
|
31
|
+
runId: RunId;
|
|
32
|
+
eventIndex: number;
|
|
33
|
+
eventType: WorkflowEvent['type'];
|
|
34
|
+
stepId?: string;
|
|
35
|
+
event: WorkflowEvent;
|
|
36
|
+
createdAt: number;
|
|
37
|
+
}
|
|
38
|
+
interface LoadedExecution {
|
|
39
|
+
run: WorkflowExecution;
|
|
40
|
+
events: ReadonlyArray<StoredWorkflowEvent>;
|
|
41
|
+
}
|
|
42
|
+
interface CreateRunArgs {
|
|
43
|
+
runId: RunId;
|
|
44
|
+
workflowId: WorkflowId;
|
|
45
|
+
workflowVersion?: WorkflowVersion;
|
|
46
|
+
input: unknown;
|
|
47
|
+
now: number;
|
|
48
|
+
}
|
|
49
|
+
type CreateRunResult = {
|
|
50
|
+
kind: 'created';
|
|
51
|
+
run: WorkflowExecution;
|
|
52
|
+
} | {
|
|
53
|
+
kind: 'existing';
|
|
54
|
+
run: WorkflowExecution;
|
|
55
|
+
};
|
|
56
|
+
interface ReadEventsArgs {
|
|
57
|
+
runId: RunId;
|
|
58
|
+
fromIndex?: number;
|
|
59
|
+
}
|
|
60
|
+
interface AppendEventsArgs {
|
|
61
|
+
runId: RunId;
|
|
62
|
+
expectedNextIndex: number;
|
|
63
|
+
events: ReadonlyArray<WorkflowEvent>;
|
|
64
|
+
}
|
|
65
|
+
interface AppendEventsResult {
|
|
66
|
+
nextIndex: number;
|
|
67
|
+
}
|
|
68
|
+
interface ClaimRunArgs {
|
|
69
|
+
runId: RunId;
|
|
70
|
+
leaseOwner: LeaseOwner;
|
|
71
|
+
leaseMs: number;
|
|
72
|
+
now: number;
|
|
73
|
+
}
|
|
74
|
+
type ClaimRunResult = {
|
|
75
|
+
kind: 'claimed';
|
|
76
|
+
run: WorkflowExecution;
|
|
77
|
+
} | {
|
|
78
|
+
kind: 'not-found';
|
|
79
|
+
} | {
|
|
80
|
+
kind: 'not-claimable';
|
|
81
|
+
run: WorkflowExecution;
|
|
82
|
+
};
|
|
83
|
+
interface HeartbeatRunLeaseArgs {
|
|
84
|
+
runId: RunId;
|
|
85
|
+
leaseOwner: LeaseOwner;
|
|
86
|
+
leaseMs: number;
|
|
87
|
+
now: number;
|
|
88
|
+
}
|
|
89
|
+
interface ReleaseRunLeaseArgs {
|
|
90
|
+
runId: RunId;
|
|
91
|
+
leaseOwner: LeaseOwner;
|
|
92
|
+
}
|
|
93
|
+
interface MarkRunPausedArgs {
|
|
94
|
+
runId: RunId;
|
|
95
|
+
waitingFor?: RunState['waitingFor'];
|
|
96
|
+
pendingApproval?: RunState['pendingApproval'];
|
|
97
|
+
wakeAt?: number;
|
|
98
|
+
now: number;
|
|
99
|
+
}
|
|
100
|
+
interface MarkRunFinishedArgs {
|
|
101
|
+
runId: RunId;
|
|
102
|
+
output: unknown;
|
|
103
|
+
now: number;
|
|
104
|
+
}
|
|
105
|
+
interface MarkRunErroredArgs {
|
|
106
|
+
runId: RunId;
|
|
107
|
+
error: SerializedError;
|
|
108
|
+
code: string;
|
|
109
|
+
now: number;
|
|
110
|
+
}
|
|
111
|
+
interface ScheduleTimerArgs {
|
|
112
|
+
runId: RunId;
|
|
113
|
+
workflowId: WorkflowId;
|
|
114
|
+
workflowVersion?: WorkflowVersion;
|
|
115
|
+
wakeAt: number;
|
|
116
|
+
signalId: string;
|
|
117
|
+
now: number;
|
|
118
|
+
}
|
|
119
|
+
interface ClaimDueTimersArgs {
|
|
120
|
+
now: number;
|
|
121
|
+
limit: number;
|
|
122
|
+
leaseOwner: LeaseOwner;
|
|
123
|
+
leaseMs: number;
|
|
124
|
+
}
|
|
125
|
+
interface TimerWakeup {
|
|
126
|
+
runId: RunId;
|
|
127
|
+
workflowId: WorkflowId;
|
|
128
|
+
workflowVersion?: WorkflowVersion;
|
|
129
|
+
wakeAt: number;
|
|
130
|
+
signalId: string;
|
|
131
|
+
}
|
|
132
|
+
interface DeliverSignalArgs<TPayload = unknown> {
|
|
133
|
+
runId: RunId;
|
|
134
|
+
delivery: SignalDelivery<TPayload>;
|
|
135
|
+
now: number;
|
|
136
|
+
}
|
|
137
|
+
type DeliverSignalResult = {
|
|
138
|
+
kind: 'delivered';
|
|
139
|
+
run: WorkflowExecution;
|
|
140
|
+
} | {
|
|
141
|
+
kind: 'duplicate';
|
|
142
|
+
run: WorkflowExecution;
|
|
143
|
+
} | {
|
|
144
|
+
kind: 'not-waiting';
|
|
145
|
+
run: WorkflowExecution;
|
|
146
|
+
} | {
|
|
147
|
+
kind: 'not-found';
|
|
148
|
+
};
|
|
149
|
+
interface DeliverApprovalArgs {
|
|
150
|
+
runId: RunId;
|
|
151
|
+
approval: ApprovalResult;
|
|
152
|
+
now: number;
|
|
153
|
+
}
|
|
154
|
+
type DeliverApprovalResult = {
|
|
155
|
+
kind: 'delivered';
|
|
156
|
+
run: WorkflowExecution;
|
|
157
|
+
} | {
|
|
158
|
+
kind: 'duplicate';
|
|
159
|
+
run: WorkflowExecution;
|
|
160
|
+
} | {
|
|
161
|
+
kind: 'not-waiting';
|
|
162
|
+
run: WorkflowExecution;
|
|
163
|
+
} | {
|
|
164
|
+
kind: 'not-found';
|
|
165
|
+
};
|
|
166
|
+
type WorkflowOverlapPolicy = 'skip' | 'allow' | 'buffer-one' | 'cancel-previous' | 'terminate-previous';
|
|
167
|
+
type WorkflowScheduleSpec = {
|
|
168
|
+
kind: 'cron';
|
|
169
|
+
expression: string;
|
|
170
|
+
timezone?: string;
|
|
171
|
+
} | {
|
|
172
|
+
kind: 'interval';
|
|
173
|
+
everyMs: number;
|
|
174
|
+
timezone?: string;
|
|
175
|
+
};
|
|
176
|
+
interface WorkflowScheduleDefinition {
|
|
177
|
+
id?: ScheduleId;
|
|
178
|
+
schedule: WorkflowScheduleSpec;
|
|
179
|
+
overlapPolicy?: WorkflowOverlapPolicy;
|
|
180
|
+
input?: unknown | (() => unknown | Promise<unknown>);
|
|
181
|
+
enabled?: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface UpsertScheduleArgs {
|
|
184
|
+
scheduleId: ScheduleId;
|
|
185
|
+
workflowId: WorkflowId;
|
|
186
|
+
workflowVersion?: WorkflowVersion;
|
|
187
|
+
schedule: WorkflowScheduleSpec;
|
|
188
|
+
overlapPolicy: WorkflowOverlapPolicy;
|
|
189
|
+
input?: unknown;
|
|
190
|
+
nextFireAt?: number;
|
|
191
|
+
enabled: boolean;
|
|
192
|
+
now: number;
|
|
193
|
+
}
|
|
194
|
+
interface ClaimDueScheduleBucketsArgs {
|
|
195
|
+
now: number;
|
|
196
|
+
limit: number;
|
|
197
|
+
leaseOwner: LeaseOwner;
|
|
198
|
+
leaseMs: number;
|
|
199
|
+
}
|
|
200
|
+
interface ScheduleBucket {
|
|
201
|
+
scheduleId: ScheduleId;
|
|
202
|
+
bucketId: ScheduleBucketId;
|
|
203
|
+
workflowId: WorkflowId;
|
|
204
|
+
workflowVersion?: WorkflowVersion;
|
|
205
|
+
runId: RunId;
|
|
206
|
+
fireAt: number;
|
|
207
|
+
input: unknown;
|
|
208
|
+
overlapPolicy: WorkflowOverlapPolicy;
|
|
209
|
+
}
|
|
210
|
+
interface MarkScheduleBucketStartedArgs {
|
|
211
|
+
scheduleId: ScheduleId;
|
|
212
|
+
bucketId: ScheduleBucketId;
|
|
213
|
+
runId: RunId;
|
|
214
|
+
now: number;
|
|
215
|
+
}
|
|
216
|
+
interface ClaimStaleRunsArgs {
|
|
217
|
+
now: number;
|
|
218
|
+
limit: number;
|
|
219
|
+
leaseOwner: LeaseOwner;
|
|
220
|
+
leaseMs: number;
|
|
221
|
+
}
|
|
222
|
+
interface RunClaim {
|
|
223
|
+
run: WorkflowExecution;
|
|
224
|
+
lease: WorkflowLease;
|
|
225
|
+
}
|
|
226
|
+
interface ListRunsArgs {
|
|
227
|
+
workflowId?: WorkflowId;
|
|
228
|
+
status?: WorkflowExecutionStatus;
|
|
229
|
+
limit: number;
|
|
230
|
+
cursor?: string;
|
|
231
|
+
}
|
|
232
|
+
interface RunSummary {
|
|
233
|
+
runId: RunId;
|
|
234
|
+
workflowId: WorkflowId;
|
|
235
|
+
workflowVersion?: WorkflowVersion;
|
|
236
|
+
status: WorkflowExecutionStatus;
|
|
237
|
+
waitingFor?: RunState['waitingFor'];
|
|
238
|
+
pendingApproval?: RunState['pendingApproval'];
|
|
239
|
+
wakeAt?: number;
|
|
240
|
+
createdAt: number;
|
|
241
|
+
updatedAt: number;
|
|
242
|
+
}
|
|
243
|
+
interface RunTimeline {
|
|
244
|
+
run: WorkflowExecution;
|
|
245
|
+
events: ReadonlyArray<StoredWorkflowEvent>;
|
|
246
|
+
}
|
|
247
|
+
interface SaveRunStateArgs {
|
|
248
|
+
state: RunState;
|
|
249
|
+
}
|
|
250
|
+
interface WorkflowRunStoreAdapterStore {
|
|
251
|
+
loadRunState: (runId: RunId) => Promise<RunState | undefined>;
|
|
252
|
+
saveRunState: (args: SaveRunStateArgs) => Promise<void>;
|
|
253
|
+
deleteRun: (runId: RunId, reason: DeleteReason) => Promise<void>;
|
|
254
|
+
appendEvents: (args: AppendEventsArgs) => Promise<AppendEventsResult>;
|
|
255
|
+
readEvents: (args: ReadEventsArgs) => Promise<ReadonlyArray<StoredWorkflowEvent>>;
|
|
256
|
+
subscribeEvents?: (runId: RunId, fromIndex: number, onEvent: (event: WorkflowEvent, index: number) => void) => () => void;
|
|
257
|
+
}
|
|
258
|
+
type WorkflowRunStoreAdapter = RunStore;
|
|
259
|
+
interface WorkflowExecutionStore extends WorkflowRunStoreAdapterStore {
|
|
260
|
+
createRun: (args: CreateRunArgs) => Promise<CreateRunResult>;
|
|
261
|
+
loadRun: (runId: RunId) => Promise<WorkflowExecution | undefined>;
|
|
262
|
+
loadExecution: (runId: RunId) => Promise<LoadedExecution | undefined>;
|
|
263
|
+
claimRun: (args: ClaimRunArgs) => Promise<ClaimRunResult>;
|
|
264
|
+
heartbeatRunLease: (args: HeartbeatRunLeaseArgs) => Promise<void>;
|
|
265
|
+
releaseRunLease: (args: ReleaseRunLeaseArgs) => Promise<void>;
|
|
266
|
+
markRunPaused: (args: MarkRunPausedArgs) => Promise<void>;
|
|
267
|
+
markRunFinished: (args: MarkRunFinishedArgs) => Promise<void>;
|
|
268
|
+
markRunErrored: (args: MarkRunErroredArgs) => Promise<void>;
|
|
269
|
+
scheduleTimer: (args: ScheduleTimerArgs) => Promise<void>;
|
|
270
|
+
claimDueTimers: (args: ClaimDueTimersArgs) => Promise<ReadonlyArray<TimerWakeup>>;
|
|
271
|
+
deliverSignal: <TPayload = unknown>(args: DeliverSignalArgs<TPayload>) => Promise<DeliverSignalResult>;
|
|
272
|
+
deliverApproval: (args: DeliverApprovalArgs) => Promise<DeliverApprovalResult>;
|
|
273
|
+
upsertSchedule: (args: UpsertScheduleArgs) => Promise<void>;
|
|
274
|
+
claimDueScheduleBuckets: (args: ClaimDueScheduleBucketsArgs) => Promise<ReadonlyArray<ScheduleBucket>>;
|
|
275
|
+
markScheduleBucketStarted: (args: MarkScheduleBucketStartedArgs) => Promise<void>;
|
|
276
|
+
claimStaleRuns: (args: ClaimStaleRunsArgs) => Promise<ReadonlyArray<RunClaim>>;
|
|
277
|
+
listRuns: (args: ListRunsArgs) => Promise<ReadonlyArray<RunSummary>>;
|
|
278
|
+
getRunTimeline: (runId: RunId) => Promise<RunTimeline | undefined>;
|
|
279
|
+
}
|
|
280
|
+
type WorkflowLoaderResult<TWorkflow extends AnyWorkflowDefinition = AnyWorkflowDefinition> = TWorkflow | {
|
|
281
|
+
default: TWorkflow;
|
|
282
|
+
} | {
|
|
283
|
+
workflow: TWorkflow;
|
|
284
|
+
};
|
|
285
|
+
type WorkflowLoader<TWorkflow extends AnyWorkflowDefinition = AnyWorkflowDefinition> = () => Promise<WorkflowLoaderResult<TWorkflow>>;
|
|
286
|
+
interface WorkflowRegistration<TWorkflow extends AnyWorkflowDefinition = AnyWorkflowDefinition> {
|
|
287
|
+
load: WorkflowLoader<TWorkflow>;
|
|
288
|
+
version?: WorkflowVersion;
|
|
289
|
+
previousVersions?: Record<WorkflowVersion, WorkflowLoader>;
|
|
290
|
+
schedules?: ReadonlyArray<WorkflowScheduleDefinition>;
|
|
291
|
+
}
|
|
292
|
+
type WorkflowRegistrationMap = Record<string, WorkflowRegistration>;
|
|
293
|
+
interface WorkflowRuntimeConfig<TWorkflows extends WorkflowRegistrationMap = WorkflowRegistrationMap> {
|
|
294
|
+
workflows: TWorkflows;
|
|
295
|
+
store: WorkflowExecutionStore;
|
|
296
|
+
defaultLeaseMs?: number;
|
|
297
|
+
}
|
|
298
|
+
interface WorkflowRuntimeDefinition<TWorkflows extends WorkflowRegistrationMap = WorkflowRegistrationMap> extends WorkflowRuntimeConfig<TWorkflows> {
|
|
299
|
+
__kind: 'workflow-runtime';
|
|
300
|
+
startRun: (args: WorkflowRuntimeStartRunArgs) => Promise<WorkflowRuntimeRunResult>;
|
|
301
|
+
deliverSignal: <TPayload = unknown>(args: WorkflowRuntimeDeliverSignalArgs<TPayload>) => Promise<WorkflowRuntimeRunResult>;
|
|
302
|
+
deliverApproval: (args: WorkflowRuntimeDeliverApprovalArgs) => Promise<WorkflowRuntimeRunResult>;
|
|
303
|
+
sweep: (args?: WorkflowRuntimeSweepArgs) => Promise<WorkflowRuntimeSweepResult>;
|
|
304
|
+
}
|
|
305
|
+
interface WorkflowRuntimeStartRunArgs {
|
|
306
|
+
workflowId: WorkflowId;
|
|
307
|
+
runId: RunId;
|
|
308
|
+
input: unknown;
|
|
309
|
+
now?: number;
|
|
310
|
+
leaseOwner?: LeaseOwner;
|
|
311
|
+
leaseMs?: number;
|
|
312
|
+
threadId?: string;
|
|
313
|
+
includeEvents?: boolean;
|
|
314
|
+
maxEvents?: number;
|
|
315
|
+
}
|
|
316
|
+
interface WorkflowRuntimeDeliverSignalArgs<TPayload = unknown> {
|
|
317
|
+
runId: RunId;
|
|
318
|
+
signalId: string;
|
|
319
|
+
name: string;
|
|
320
|
+
payload: TPayload;
|
|
321
|
+
now?: number;
|
|
322
|
+
leaseOwner?: LeaseOwner;
|
|
323
|
+
leaseMs?: number;
|
|
324
|
+
threadId?: string;
|
|
325
|
+
includeEvents?: boolean;
|
|
326
|
+
maxEvents?: number;
|
|
327
|
+
}
|
|
328
|
+
interface WorkflowRuntimeDeliverApprovalArgs {
|
|
329
|
+
runId: RunId;
|
|
330
|
+
approval: ApprovalResult;
|
|
331
|
+
now?: number;
|
|
332
|
+
leaseOwner?: LeaseOwner;
|
|
333
|
+
leaseMs?: number;
|
|
334
|
+
threadId?: string;
|
|
335
|
+
includeEvents?: boolean;
|
|
336
|
+
maxEvents?: number;
|
|
337
|
+
}
|
|
338
|
+
type WorkflowRuntimeRunResultKind = 'completed' | 'paused' | 'errored' | 'running' | 'not-found' | 'not-claimable' | 'not-waiting' | 'duplicate';
|
|
339
|
+
interface WorkflowRuntimeRunResult {
|
|
340
|
+
kind: WorkflowRuntimeRunResultKind;
|
|
341
|
+
runId: RunId;
|
|
342
|
+
workflowId?: WorkflowId;
|
|
343
|
+
run?: WorkflowExecution;
|
|
344
|
+
events: ReadonlyArray<WorkflowEvent>;
|
|
345
|
+
eventCount: number;
|
|
346
|
+
eventsTruncated?: boolean;
|
|
347
|
+
}
|
|
348
|
+
interface WorkflowRuntimeSweepArgs {
|
|
349
|
+
now?: number;
|
|
350
|
+
limit?: number;
|
|
351
|
+
maxScheduledRuns?: number;
|
|
352
|
+
maxTimers?: number;
|
|
353
|
+
maxDurationMs?: number;
|
|
354
|
+
leaseOwner?: LeaseOwner;
|
|
355
|
+
leaseMs?: number;
|
|
356
|
+
includeEvents?: boolean;
|
|
357
|
+
maxEvents?: number;
|
|
358
|
+
}
|
|
359
|
+
interface WorkflowRuntimeSweepResult {
|
|
360
|
+
scheduled: ReadonlyArray<WorkflowRuntimeRunResult>;
|
|
361
|
+
timers: ReadonlyArray<WorkflowRuntimeRunResult>;
|
|
362
|
+
summary: WorkflowRuntimeSweepSummary;
|
|
363
|
+
deadlineReached: boolean;
|
|
364
|
+
remainingMayExist: boolean;
|
|
365
|
+
}
|
|
366
|
+
type WorkflowRuntimeRunKindCounts = Partial<Record<WorkflowRuntimeRunResultKind, number>>;
|
|
367
|
+
interface WorkflowRuntimeSweepSummary {
|
|
368
|
+
scheduled: WorkflowRuntimeRunKindCounts;
|
|
369
|
+
timers: WorkflowRuntimeRunKindCounts;
|
|
370
|
+
eventCount: number;
|
|
371
|
+
returnedEventCount: number;
|
|
372
|
+
}
|
|
373
|
+
//#endregion
|
|
374
|
+
export { AppendEventsArgs, AppendEventsResult, ClaimDueScheduleBucketsArgs, ClaimDueTimersArgs, ClaimRunArgs, ClaimRunResult, ClaimStaleRunsArgs, CreateRunArgs, CreateRunResult, DeliverApprovalArgs, DeliverApprovalResult, DeliverSignalArgs, DeliverSignalResult, HeartbeatRunLeaseArgs, LeaseOwner, ListRunsArgs, LoadedExecution, MarkRunErroredArgs, MarkRunFinishedArgs, MarkRunPausedArgs, MarkScheduleBucketStartedArgs, ReadEventsArgs, ReleaseRunLeaseArgs, RunClaim, RunId, RunSummary, RunTimeline, SaveRunStateArgs, ScheduleBucket, ScheduleBucketId, ScheduleId, ScheduleTimerArgs, StoredWorkflowEvent, TimerWakeup, UpsertScheduleArgs, WorkflowExecution, WorkflowExecutionStatus, WorkflowExecutionStore, WorkflowId, WorkflowLease, WorkflowLoader, WorkflowLoaderResult, WorkflowOverlapPolicy, WorkflowRegistration, WorkflowRegistrationMap, WorkflowRunStoreAdapter, WorkflowRunStoreAdapterStore, WorkflowRuntimeConfig, WorkflowRuntimeDefinition, WorkflowRuntimeDeliverApprovalArgs, WorkflowRuntimeDeliverSignalArgs, WorkflowRuntimeRunKindCounts, WorkflowRuntimeRunResult, WorkflowRuntimeRunResultKind, WorkflowRuntimeStartRunArgs, WorkflowRuntimeSweepArgs, WorkflowRuntimeSweepResult, WorkflowRuntimeSweepSummary, WorkflowScheduleDefinition, WorkflowScheduleSpec, WorkflowVersion };
|
|
375
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/workflow-runtime",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Runtime contracts for scheduling, durable execution stores, leases, timers, signals, and host adapters for TanStack Workflow.",
|
|
5
|
+
"author": "Tanner Linsley",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/TanStack/workflow.git",
|
|
10
|
+
"directory": "packages/workflow-runtime"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://tanstack.com/workflow",
|
|
13
|
+
"funding": {
|
|
14
|
+
"type": "github",
|
|
15
|
+
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"tanstack",
|
|
19
|
+
"workflow",
|
|
20
|
+
"durable-execution",
|
|
21
|
+
"runtime",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "premove ./build ./dist",
|
|
26
|
+
"lint": "eslint ./src",
|
|
27
|
+
"lint:fix": "eslint ./src --fix",
|
|
28
|
+
"test:eslint": "eslint ./src",
|
|
29
|
+
"test:lib": "vitest",
|
|
30
|
+
"test:lib:dev": "pnpm test:lib --watch",
|
|
31
|
+
"test:types": "tsc",
|
|
32
|
+
"build": "tsdown"
|
|
33
|
+
},
|
|
34
|
+
"type": "module",
|
|
35
|
+
"main": "./dist/index.cjs",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.cts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"import": "./dist/index.js",
|
|
41
|
+
"require": "./dist/index.cjs"
|
|
42
|
+
},
|
|
43
|
+
"./types": {
|
|
44
|
+
"import": "./dist/types.js",
|
|
45
|
+
"require": "./dist/types.cjs"
|
|
46
|
+
},
|
|
47
|
+
"./package.json": "./package.json"
|
|
48
|
+
},
|
|
49
|
+
"sideEffects": false,
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist/",
|
|
55
|
+
"src"
|
|
56
|
+
],
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@tanstack/workflow-core": "workspace:*"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRuntimeDriver } from './runtime-driver'
|
|
2
|
+
import type {
|
|
3
|
+
WorkflowRegistrationMap,
|
|
4
|
+
WorkflowRuntimeConfig,
|
|
5
|
+
WorkflowRuntimeDefinition,
|
|
6
|
+
WorkflowScheduleSpec,
|
|
7
|
+
} from './types'
|
|
8
|
+
|
|
9
|
+
export function defineWorkflowRuntime<
|
|
10
|
+
const TWorkflows extends WorkflowRegistrationMap,
|
|
11
|
+
>(
|
|
12
|
+
config: WorkflowRuntimeConfig<TWorkflows>,
|
|
13
|
+
): WorkflowRuntimeDefinition<TWorkflows> {
|
|
14
|
+
const driver = createRuntimeDriver(config)
|
|
15
|
+
return {
|
|
16
|
+
__kind: 'workflow-runtime',
|
|
17
|
+
...config,
|
|
18
|
+
...driver,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function cron(
|
|
23
|
+
expression: string,
|
|
24
|
+
options: { timezone?: string } = {},
|
|
25
|
+
): WorkflowScheduleSpec {
|
|
26
|
+
return {
|
|
27
|
+
kind: 'cron',
|
|
28
|
+
expression,
|
|
29
|
+
timezone: options.timezone,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const every = {
|
|
34
|
+
milliseconds(everyMs: number): WorkflowScheduleSpec {
|
|
35
|
+
return { kind: 'interval', everyMs }
|
|
36
|
+
},
|
|
37
|
+
seconds(seconds: number): WorkflowScheduleSpec {
|
|
38
|
+
return { kind: 'interval', everyMs: seconds * 1000 }
|
|
39
|
+
},
|
|
40
|
+
minutes(minutes: number): WorkflowScheduleSpec {
|
|
41
|
+
return { kind: 'interval', everyMs: minutes * 60 * 1000 }
|
|
42
|
+
},
|
|
43
|
+
hours(hours: number): WorkflowScheduleSpec {
|
|
44
|
+
return { kind: 'interval', everyMs: hours * 60 * 60 * 1000 }
|
|
45
|
+
},
|
|
46
|
+
}
|