@coji/durably-react 0.6.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.
@@ -0,0 +1,284 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { Durably, JobDefinition, Run } from '@coji/durably';
3
+ import { ReactNode } from 'react';
4
+ import { R as RunStatus, L as LogEntry, P as Progress } from './types-BDUvsa8u.js';
5
+ export { D as DurablyEvent } from './types-BDUvsa8u.js';
6
+
7
+ interface DurablyContextValue {
8
+ durably: Durably;
9
+ }
10
+ interface DurablyProviderProps {
11
+ /**
12
+ * Durably instance or Promise that resolves to one.
13
+ * The instance should already be initialized via `await durably.init()`.
14
+ *
15
+ * When passing a Promise, wrap the provider with Suspense or use the fallback prop.
16
+ *
17
+ * @example
18
+ * // With Suspense (recommended)
19
+ * <Suspense fallback={<Loading />}>
20
+ * <DurablyProvider durably={durablyPromise}>
21
+ * <App />
22
+ * </DurablyProvider>
23
+ * </Suspense>
24
+ *
25
+ * @example
26
+ * // With fallback prop
27
+ * <DurablyProvider durably={durablyPromise} fallback={<Loading />}>
28
+ * <App />
29
+ * </DurablyProvider>
30
+ */
31
+ durably: Durably | Promise<Durably>;
32
+ /**
33
+ * Fallback to show while waiting for the Durably Promise to resolve.
34
+ * This wraps the provider content in a Suspense boundary automatically.
35
+ */
36
+ fallback?: ReactNode;
37
+ children: ReactNode;
38
+ }
39
+ declare function DurablyProvider({ durably, fallback, children, }: DurablyProviderProps): react_jsx_runtime.JSX.Element;
40
+ declare function useDurably(): DurablyContextValue;
41
+
42
+ interface UseJobOptions {
43
+ /**
44
+ * Initial Run ID to subscribe to (for reconnection scenarios)
45
+ */
46
+ initialRunId?: string;
47
+ /**
48
+ * Automatically resume tracking any pending or running job on initialization.
49
+ * If a pending or running run exists for this job, the hook will subscribe to it.
50
+ * @default true
51
+ */
52
+ autoResume?: boolean;
53
+ /**
54
+ * Automatically switch to tracking the latest running job when a new run starts.
55
+ * When true, the hook will update to track any new run for this job as soon as it starts running.
56
+ * When false, the hook will only track the run that was triggered or explicitly set.
57
+ * @default true
58
+ */
59
+ followLatest?: boolean;
60
+ }
61
+ interface UseJobResult<TInput, TOutput> {
62
+ /**
63
+ * Trigger the job with the given input
64
+ */
65
+ trigger: (input: TInput) => Promise<{
66
+ runId: string;
67
+ }>;
68
+ /**
69
+ * Trigger and wait for completion
70
+ */
71
+ triggerAndWait: (input: TInput) => Promise<{
72
+ runId: string;
73
+ output: TOutput;
74
+ }>;
75
+ /**
76
+ * Current run status
77
+ */
78
+ status: RunStatus | null;
79
+ /**
80
+ * Output from completed run
81
+ */
82
+ output: TOutput | null;
83
+ /**
84
+ * Error message from failed run
85
+ */
86
+ error: string | null;
87
+ /**
88
+ * Logs collected during execution
89
+ */
90
+ logs: LogEntry[];
91
+ /**
92
+ * Current progress
93
+ */
94
+ progress: Progress | null;
95
+ /**
96
+ * Whether a run is currently running
97
+ */
98
+ isRunning: boolean;
99
+ /**
100
+ * Whether a run is pending
101
+ */
102
+ isPending: boolean;
103
+ /**
104
+ * Whether the run completed successfully
105
+ */
106
+ isCompleted: boolean;
107
+ /**
108
+ * Whether the run failed
109
+ */
110
+ isFailed: boolean;
111
+ /**
112
+ * Whether the run was cancelled
113
+ */
114
+ isCancelled: boolean;
115
+ /**
116
+ * Current run ID
117
+ */
118
+ currentRunId: string | null;
119
+ /**
120
+ * Reset all state
121
+ */
122
+ reset: () => void;
123
+ }
124
+ declare function useJob<TName extends string, TInput extends Record<string, unknown>, TOutput extends Record<string, unknown> | void>(jobDefinition: JobDefinition<TName, TInput, TOutput>, options?: UseJobOptions): UseJobResult<TInput, TOutput>;
125
+
126
+ interface UseJobLogsOptions {
127
+ /**
128
+ * The run ID to subscribe to logs for
129
+ */
130
+ runId: string | null;
131
+ /**
132
+ * Maximum number of logs to keep (default: unlimited)
133
+ */
134
+ maxLogs?: number;
135
+ }
136
+ interface UseJobLogsResult {
137
+ /**
138
+ * Logs collected during execution
139
+ */
140
+ logs: LogEntry[];
141
+ /**
142
+ * Clear all logs
143
+ */
144
+ clearLogs: () => void;
145
+ }
146
+ /**
147
+ * Hook for subscribing to logs from a run.
148
+ * Use this when you only need logs, not full run status.
149
+ */
150
+ declare function useJobLogs(options: UseJobLogsOptions): UseJobLogsResult;
151
+
152
+ interface UseJobRunOptions {
153
+ /**
154
+ * The run ID to subscribe to
155
+ */
156
+ runId: string | null;
157
+ }
158
+ interface UseJobRunResult<TOutput = unknown> {
159
+ /**
160
+ * Current run status
161
+ */
162
+ status: RunStatus | null;
163
+ /**
164
+ * Output from completed run
165
+ */
166
+ output: TOutput | null;
167
+ /**
168
+ * Error message from failed run
169
+ */
170
+ error: string | null;
171
+ /**
172
+ * Logs collected during execution
173
+ */
174
+ logs: LogEntry[];
175
+ /**
176
+ * Current progress
177
+ */
178
+ progress: Progress | null;
179
+ /**
180
+ * Whether a run is currently running
181
+ */
182
+ isRunning: boolean;
183
+ /**
184
+ * Whether a run is pending
185
+ */
186
+ isPending: boolean;
187
+ /**
188
+ * Whether the run completed successfully
189
+ */
190
+ isCompleted: boolean;
191
+ /**
192
+ * Whether the run failed
193
+ */
194
+ isFailed: boolean;
195
+ /**
196
+ * Whether the run was cancelled
197
+ */
198
+ isCancelled: boolean;
199
+ }
200
+ /**
201
+ * Hook for subscribing to an existing run by ID.
202
+ * Use this when you have a runId and want to track its status.
203
+ */
204
+ declare function useJobRun<TOutput = unknown>(options: UseJobRunOptions): UseJobRunResult<TOutput>;
205
+
206
+ interface UseRunsOptions {
207
+ /**
208
+ * Filter by job name
209
+ */
210
+ jobName?: string;
211
+ /**
212
+ * Filter by status
213
+ */
214
+ status?: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
215
+ /**
216
+ * Number of runs per page
217
+ * @default 10
218
+ */
219
+ pageSize?: number;
220
+ /**
221
+ * Subscribe to real-time updates
222
+ * @default true
223
+ */
224
+ realtime?: boolean;
225
+ }
226
+ interface UseRunsResult {
227
+ /**
228
+ * List of runs for the current page
229
+ */
230
+ runs: Run[];
231
+ /**
232
+ * Current page (0-indexed)
233
+ */
234
+ page: number;
235
+ /**
236
+ * Whether there are more pages
237
+ */
238
+ hasMore: boolean;
239
+ /**
240
+ * Whether data is being loaded
241
+ */
242
+ isLoading: boolean;
243
+ /**
244
+ * Go to the next page
245
+ */
246
+ nextPage: () => void;
247
+ /**
248
+ * Go to the previous page
249
+ */
250
+ prevPage: () => void;
251
+ /**
252
+ * Go to a specific page
253
+ */
254
+ goToPage: (page: number) => void;
255
+ /**
256
+ * Refresh the current page
257
+ */
258
+ refresh: () => Promise<void>;
259
+ }
260
+ /**
261
+ * Hook for listing runs with pagination and real-time updates.
262
+ *
263
+ * @example
264
+ * ```tsx
265
+ * function Dashboard() {
266
+ * const { runs, page, hasMore, nextPage, prevPage, isLoading } = useRuns({
267
+ * pageSize: 20,
268
+ * })
269
+ *
270
+ * return (
271
+ * <div>
272
+ * {runs.map(run => (
273
+ * <div key={run.id}>{run.jobName}: {run.status}</div>
274
+ * ))}
275
+ * <button onClick={prevPage} disabled={page === 0}>Prev</button>
276
+ * <button onClick={nextPage} disabled={!hasMore}>Next</button>
277
+ * </div>
278
+ * )
279
+ * }
280
+ * ```
281
+ */
282
+ declare function useRuns(options?: UseRunsOptions): UseRunsResult;
283
+
284
+ export { DurablyProvider, type DurablyProviderProps, LogEntry, Progress, RunStatus, type UseJobLogsOptions, type UseJobLogsResult, type UseJobOptions, type UseJobResult, type UseJobRunOptions, type UseJobRunResult, type UseRunsOptions, type UseRunsResult, useDurably, useJob, useJobLogs, useJobRun, useRuns };