@coji/durably-react 0.10.0 → 0.12.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 DELETED
@@ -1,515 +0,0 @@
1
- import { R as RunStatus, L as LogEntry, P as Progress, I as InferInput, a as InferOutput, b as TypedClientRun } from './types-xrRs7jov.js';
2
- import { JobDefinition, ClientRun } from '@coji/durably';
3
- export { ClientRun } from '@coji/durably';
4
-
5
- interface UseJobClientOptions {
6
- /**
7
- * API endpoint URL (e.g., '/api/durably')
8
- */
9
- api: string;
10
- /**
11
- * Job name to trigger
12
- */
13
- jobName: string;
14
- /**
15
- * Initial Run ID to subscribe to (for reconnection scenarios)
16
- * When provided, the hook will immediately start subscribing to this run
17
- */
18
- initialRunId?: string;
19
- /**
20
- * Automatically resume tracking a running/pending job on mount
21
- * @default true
22
- */
23
- autoResume?: boolean;
24
- /**
25
- * Automatically switch to tracking the latest triggered job
26
- * @default true
27
- */
28
- followLatest?: boolean;
29
- }
30
- interface UseJobClientResult<TInput, TOutput> {
31
- /**
32
- * Whether the hook is ready (always true for client mode)
33
- */
34
- /**
35
- * Trigger the job with the given input
36
- */
37
- trigger: (input: TInput) => Promise<{
38
- runId: string;
39
- }>;
40
- /**
41
- * Trigger and wait for completion
42
- */
43
- triggerAndWait: (input: TInput) => Promise<{
44
- runId: string;
45
- output: TOutput;
46
- }>;
47
- /**
48
- * Current run status
49
- */
50
- status: RunStatus | null;
51
- /**
52
- * Output from completed run
53
- */
54
- output: TOutput | null;
55
- /**
56
- * Error message from failed run
57
- */
58
- error: string | null;
59
- /**
60
- * Logs collected during execution
61
- */
62
- logs: LogEntry[];
63
- /**
64
- * Current progress
65
- */
66
- progress: Progress | null;
67
- /**
68
- * Whether a run is currently running
69
- */
70
- isRunning: boolean;
71
- /**
72
- * Whether a run is pending
73
- */
74
- isPending: boolean;
75
- /**
76
- * Whether the run completed successfully
77
- */
78
- isCompleted: boolean;
79
- /**
80
- * Whether the run failed
81
- */
82
- isFailed: boolean;
83
- /**
84
- * Whether the run was cancelled
85
- */
86
- isCancelled: boolean;
87
- /**
88
- * Current run ID
89
- */
90
- currentRunId: string | null;
91
- /**
92
- * Reset all state
93
- */
94
- reset: () => void;
95
- }
96
- /**
97
- * Hook for triggering and subscribing to jobs via server API.
98
- * Uses fetch for triggering and EventSource for SSE subscription.
99
- */
100
- declare function useJob<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput extends Record<string, unknown> = Record<string, unknown>>(options: UseJobClientOptions): UseJobClientResult<TInput, TOutput>;
101
-
102
- interface UseJobLogsClientOptions {
103
- /**
104
- * API endpoint URL (e.g., '/api/durably')
105
- */
106
- api: string;
107
- /**
108
- * The run ID to subscribe to logs for
109
- */
110
- runId: string | null;
111
- /**
112
- * Maximum number of logs to keep (default: unlimited)
113
- */
114
- maxLogs?: number;
115
- }
116
- interface UseJobLogsClientResult {
117
- /**
118
- * Whether the hook is ready (always true for client mode)
119
- */
120
- /**
121
- * Logs collected during execution
122
- */
123
- logs: LogEntry[];
124
- /**
125
- * Clear all logs
126
- */
127
- clearLogs: () => void;
128
- }
129
- /**
130
- * Hook for subscribing to logs from a run via server API.
131
- * Uses EventSource for SSE subscription.
132
- */
133
- declare function useJobLogs(options: UseJobLogsClientOptions): UseJobLogsClientResult;
134
-
135
- interface UseJobRunClientOptions {
136
- /**
137
- * API endpoint URL (e.g., '/api/durably')
138
- */
139
- api: string;
140
- /**
141
- * The run ID to subscribe to
142
- */
143
- runId: string | null;
144
- /**
145
- * Callback when run starts (transitions to pending/running)
146
- */
147
- onStart?: () => void;
148
- /**
149
- * Callback when run completes successfully
150
- */
151
- onComplete?: () => void;
152
- /**
153
- * Callback when run fails
154
- */
155
- onFail?: () => void;
156
- }
157
- interface UseJobRunClientResult<TOutput = unknown> {
158
- /**
159
- * Whether the hook is ready (always true for client mode)
160
- */
161
- /**
162
- * Current run status
163
- */
164
- status: RunStatus | null;
165
- /**
166
- * Output from completed run
167
- */
168
- output: TOutput | null;
169
- /**
170
- * Error message from failed run
171
- */
172
- error: string | null;
173
- /**
174
- * Logs collected during execution
175
- */
176
- logs: LogEntry[];
177
- /**
178
- * Current progress
179
- */
180
- progress: Progress | null;
181
- /**
182
- * Whether a run is currently running
183
- */
184
- isRunning: boolean;
185
- /**
186
- * Whether a run is pending
187
- */
188
- isPending: boolean;
189
- /**
190
- * Whether the run completed successfully
191
- */
192
- isCompleted: boolean;
193
- /**
194
- * Whether the run failed
195
- */
196
- isFailed: boolean;
197
- /**
198
- * Whether the run was cancelled
199
- */
200
- isCancelled: boolean;
201
- }
202
- /**
203
- * Hook for subscribing to an existing run via server API.
204
- * Uses EventSource for SSE subscription.
205
- */
206
- declare function useJobRun<TOutput = unknown>(options: UseJobRunClientOptions): UseJobRunClientResult<TOutput>;
207
-
208
- /**
209
- * Type-safe hooks for a specific job
210
- */
211
- interface JobClient<TInput, TOutput> {
212
- /**
213
- * Hook for triggering and monitoring the job
214
- */
215
- useJob: () => UseJobClientResult<TInput, TOutput>;
216
- /**
217
- * Hook for subscribing to an existing run by ID
218
- */
219
- useRun: (runId: string | null) => UseJobRunClientResult<TOutput>;
220
- /**
221
- * Hook for subscribing to logs from a run
222
- */
223
- useLogs: (runId: string | null, options?: {
224
- maxLogs?: number;
225
- }) => UseJobLogsClientResult;
226
- }
227
- /**
228
- * Options for createDurablyClient
229
- */
230
- interface CreateDurablyClientOptions {
231
- /**
232
- * API endpoint URL (e.g., '/api/durably')
233
- */
234
- api: string;
235
- }
236
- /**
237
- * A type-safe client with hooks for each registered job
238
- */
239
- type DurablyClient<TJobs extends Record<string, unknown>> = {
240
- [K in keyof TJobs]: JobClient<InferInput<TJobs[K]>, InferOutput<TJobs[K]>>;
241
- };
242
- /**
243
- * Create a type-safe Durably client with hooks for all registered jobs.
244
- *
245
- * @example
246
- * ```tsx
247
- * // Server: register jobs
248
- * // app/lib/durably.server.ts
249
- * export const jobs = durably.register({
250
- * importCsv: importCsvJob,
251
- * syncUsers: syncUsersJob,
252
- * })
253
- *
254
- * // Client: create typed client
255
- * // app/lib/durably.client.ts
256
- * import type { jobs } from '~/lib/durably.server'
257
- * import { createDurablyClient } from '@coji/durably-react/client'
258
- *
259
- * export const durably = createDurablyClient<typeof jobs>({
260
- * api: '/api/durably',
261
- * })
262
- *
263
- * // In your component - fully type-safe with autocomplete
264
- * function CsvImporter() {
265
- * const { trigger, output, isRunning } = durably.importCsv.useJob()
266
- *
267
- * return (
268
- * <button onClick={() => trigger({ rows: [...] })}>
269
- * Import
270
- * </button>
271
- * )
272
- * }
273
- * ```
274
- */
275
- declare function createDurablyClient<TJobs extends Record<string, unknown>>(options: CreateDurablyClientOptions): DurablyClient<TJobs>;
276
-
277
- /**
278
- * Options for createJobHooks
279
- */
280
- interface CreateJobHooksOptions {
281
- /**
282
- * API endpoint URL (e.g., '/api/durably')
283
- */
284
- api: string;
285
- /**
286
- * Job name (must match the server-side job name)
287
- */
288
- jobName: string;
289
- }
290
- /**
291
- * Type-safe hooks for a specific job
292
- */
293
- interface JobHooks<TInput, TOutput> {
294
- /**
295
- * Hook for triggering and monitoring the job
296
- */
297
- useJob: () => UseJobClientResult<TInput, TOutput>;
298
- /**
299
- * Hook for subscribing to an existing run by ID
300
- */
301
- useRun: (runId: string | null) => UseJobRunClientResult<TOutput>;
302
- /**
303
- * Hook for subscribing to logs from a run
304
- */
305
- useLogs: (runId: string | null, options?: {
306
- maxLogs?: number;
307
- }) => UseJobLogsClientResult;
308
- }
309
- /**
310
- * Create type-safe hooks for a specific job.
311
- *
312
- * @example
313
- * ```tsx
314
- * // Import job type from server (type-only import is safe)
315
- * import type { importCsvJob } from '~/lib/durably.server'
316
- * import { createJobHooks } from '@coji/durably-react/client'
317
- *
318
- * const importCsv = createJobHooks<typeof importCsvJob>({
319
- * api: '/api/durably',
320
- * jobName: 'import-csv',
321
- * })
322
- *
323
- * // In your component - fully type-safe
324
- * function CsvImporter() {
325
- * const { trigger, output, progress, isRunning } = importCsv.useJob()
326
- *
327
- * return (
328
- * <button onClick={() => trigger({ rows: [...] })}>
329
- * Import
330
- * </button>
331
- * )
332
- * }
333
- * ```
334
- */
335
- declare function createJobHooks<TJob extends JobDefinition<string, any, any>>(options: CreateJobHooksOptions): JobHooks<InferInput<TJob>, InferOutput<TJob>>;
336
-
337
- interface UseRunsClientOptions {
338
- /**
339
- * API endpoint URL (e.g., '/api/durably')
340
- */
341
- api: string;
342
- /**
343
- * Filter by job name
344
- */
345
- jobName?: string;
346
- /**
347
- * Filter by status
348
- */
349
- status?: RunStatus;
350
- /**
351
- * Filter by labels (all specified labels must match)
352
- */
353
- labels?: Record<string, string>;
354
- /**
355
- * Number of runs per page
356
- * @default 10
357
- */
358
- pageSize?: number;
359
- /**
360
- * Subscribe to real-time updates via SSE (first page only)
361
- * @default true
362
- */
363
- realtime?: boolean;
364
- }
365
- interface UseRunsClientResult<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> {
366
- /**
367
- * List of runs for the current page
368
- */
369
- runs: TypedClientRun<TInput, TOutput>[];
370
- /**
371
- * Current page (0-indexed)
372
- */
373
- page: number;
374
- /**
375
- * Whether there are more pages
376
- */
377
- hasMore: boolean;
378
- /**
379
- * Whether data is being loaded
380
- */
381
- isLoading: boolean;
382
- /**
383
- * Error message if fetch failed
384
- */
385
- error: string | null;
386
- /**
387
- * Go to the next page
388
- */
389
- nextPage: () => void;
390
- /**
391
- * Go to the previous page
392
- */
393
- prevPage: () => void;
394
- /**
395
- * Go to a specific page
396
- */
397
- goToPage: (page: number) => void;
398
- /**
399
- * Refresh the current page
400
- */
401
- refresh: () => Promise<void>;
402
- }
403
- /**
404
- * Hook for listing runs via server API with pagination.
405
- * First page (page 0) automatically subscribes to SSE for real-time updates.
406
- * Other pages are static and require manual refresh.
407
- *
408
- * @example With generic type parameter (dashboard with multiple job types)
409
- * ```tsx
410
- * type DashboardRun = TypedClientRun<ImportInput, ImportOutput> | TypedClientRun<SyncInput, SyncOutput>
411
- *
412
- * function Dashboard() {
413
- * const { runs } = useRuns<DashboardRun>({ api: '/api/durably', pageSize: 10 })
414
- * // runs are typed as DashboardRun[]
415
- * }
416
- * ```
417
- *
418
- * @example With JobDefinition (single job, auto-filters by jobName)
419
- * ```tsx
420
- * const myJob = defineJob({ name: 'my-job', ... })
421
- *
422
- * function RunHistory() {
423
- * const { runs } = useRuns(myJob, { api: '/api/durably' })
424
- * // runs[0].output is typed!
425
- * return <div>{runs[0]?.output?.someField}</div>
426
- * }
427
- * ```
428
- *
429
- * @example With options only (untyped)
430
- * ```tsx
431
- * function RunHistory() {
432
- * const { runs } = useRuns({ api: '/api/durably', pageSize: 10 })
433
- * // runs[0].output is unknown
434
- * }
435
- * ```
436
- */
437
- declare function useRuns<TRun extends TypedClientRun<Record<string, unknown>, Record<string, unknown> | undefined>>(options: UseRunsClientOptions): UseRunsClientResult<TRun extends TypedClientRun<infer I, infer _O> ? I : Record<string, unknown>, TRun extends TypedClientRun<infer _I, infer O> ? O : Record<string, unknown>>;
438
- declare function useRuns<TName extends string, TInput extends Record<string, unknown>, TOutput extends Record<string, unknown> | undefined>(jobDefinition: JobDefinition<TName, TInput, TOutput>, options: Omit<UseRunsClientOptions, 'jobName'>): UseRunsClientResult<TInput, TOutput>;
439
- declare function useRuns(options: UseRunsClientOptions): UseRunsClientResult;
440
-
441
- /**
442
- * Step record returned from the server API
443
- */
444
- interface StepRecord {
445
- name: string;
446
- status: 'completed' | 'failed' | 'cancelled';
447
- output: unknown;
448
- }
449
- interface UseRunActionsClientOptions {
450
- /**
451
- * API endpoint URL (e.g., '/api/durably')
452
- */
453
- api: string;
454
- }
455
- interface UseRunActionsClientResult {
456
- /**
457
- * Retry a failed or cancelled run
458
- */
459
- retry: (runId: string) => Promise<void>;
460
- /**
461
- * Cancel a pending or running run
462
- */
463
- cancel: (runId: string) => Promise<void>;
464
- /**
465
- * Delete a run (only completed, failed, or cancelled runs)
466
- */
467
- deleteRun: (runId: string) => Promise<void>;
468
- /**
469
- * Get a single run by ID
470
- */
471
- getRun: (runId: string) => Promise<ClientRun | null>;
472
- /**
473
- * Get steps for a run
474
- */
475
- getSteps: (runId: string) => Promise<StepRecord[]>;
476
- /**
477
- * Whether an action is in progress
478
- */
479
- isLoading: boolean;
480
- /**
481
- * Error message from last action
482
- */
483
- error: string | null;
484
- }
485
- /**
486
- * Hook for run actions (retry, cancel) via server API.
487
- *
488
- * @example
489
- * ```tsx
490
- * function RunActions({ runId, status }: { runId: string; status: string }) {
491
- * const { retry, cancel, isLoading, error } = useRunActions({
492
- * api: '/api/durably',
493
- * })
494
- *
495
- * return (
496
- * <div>
497
- * {status === 'failed' && (
498
- * <button onClick={() => retry(runId)} disabled={isLoading}>
499
- * Retry
500
- * </button>
501
- * )}
502
- * {(status === 'pending' || status === 'running') && (
503
- * <button onClick={() => cancel(runId)} disabled={isLoading}>
504
- * Cancel
505
- * </button>
506
- * )}
507
- * {error && <span className="error">{error}</span>}
508
- * </div>
509
- * )
510
- * }
511
- * ```
512
- */
513
- declare function useRunActions(options: UseRunActionsClientOptions): UseRunActionsClientResult;
514
-
515
- export { type CreateDurablyClientOptions, type CreateJobHooksOptions, type DurablyClient, type JobClient, type JobHooks, LogEntry, Progress, RunStatus, type StepRecord, TypedClientRun, type UseJobClientOptions, type UseJobClientResult, type UseJobLogsClientOptions, type UseJobLogsClientResult, type UseJobRunClientOptions, type UseJobRunClientResult, type UseRunActionsClientOptions, type UseRunActionsClientResult, type UseRunsClientOptions, type UseRunsClientResult, createDurablyClient, createJobHooks, useJob, useJobLogs, useJobRun, useRunActions, useRuns };