@coji/durably-react 0.6.0 → 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/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { Durably, JobDefinition, Run } from '@coji/durably';
2
+ import { Durably, JobDefinition } from '@coji/durably';
3
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';
4
+ import { R as RunStatus, L as LogEntry, P as Progress, T as TypedRun } from './types-DY4Y6ggJ.js';
5
+ export { D as DurablyEvent } from './types-DY4Y6ggJ.js';
6
6
 
7
7
  interface DurablyContextValue {
8
8
  durably: Durably;
@@ -223,11 +223,11 @@ interface UseRunsOptions {
223
223
  */
224
224
  realtime?: boolean;
225
225
  }
226
- interface UseRunsResult {
226
+ interface UseRunsResult<TInput extends Record<string, unknown> = Record<string, unknown>, TOutput extends Record<string, unknown> | undefined = Record<string, unknown> | undefined> {
227
227
  /**
228
228
  * List of runs for the current page
229
229
  */
230
- runs: Run[];
230
+ runs: TypedRun<TInput, TOutput>[];
231
231
  /**
232
232
  * Current page (0-indexed)
233
233
  */
@@ -260,25 +260,37 @@ interface UseRunsResult {
260
260
  /**
261
261
  * Hook for listing runs with pagination and real-time updates.
262
262
  *
263
- * @example
263
+ * @example With generic type parameter (dashboard with multiple job types)
264
264
  * ```tsx
265
+ * type DashboardRun = TypedRun<ImportInput, ImportOutput> | TypedRun<SyncInput, SyncOutput>
266
+ *
265
267
  * function Dashboard() {
266
- * const { runs, page, hasMore, nextPage, prevPage, isLoading } = useRuns({
267
- * pageSize: 20,
268
- * })
268
+ * const { runs } = useRuns<DashboardRun>({ pageSize: 10 })
269
+ * // runs are typed as DashboardRun[]
270
+ * }
271
+ * ```
269
272
  *
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
- * )
273
+ * @example With JobDefinition (single job, auto-filters by jobName)
274
+ * ```tsx
275
+ * const myJob = defineJob({ name: 'my-job', ... })
276
+ *
277
+ * function Dashboard() {
278
+ * const { runs } = useRuns(myJob)
279
+ * // runs[0].output is typed!
280
+ * return <div>{runs[0]?.output?.someField}</div>
281
+ * }
282
+ * ```
283
+ *
284
+ * @example With options only (untyped)
285
+ * ```tsx
286
+ * function Dashboard() {
287
+ * const { runs } = useRuns({ pageSize: 20 })
288
+ * // runs[0].output is unknown
279
289
  * }
280
290
  * ```
281
291
  */
292
+ declare function useRuns<TRun extends TypedRun<Record<string, unknown>, Record<string, unknown> | undefined>>(options?: UseRunsOptions): UseRunsResult<TRun extends TypedRun<infer I, infer _O> ? I : Record<string, unknown>, TRun extends TypedRun<infer _I, infer O> ? O : Record<string, unknown>>;
293
+ declare function useRuns<TName extends string, TInput extends Record<string, unknown>, TOutput extends Record<string, unknown> | undefined>(jobDefinition: JobDefinition<TName, TInput, TOutput>, options?: Omit<UseRunsOptions, 'jobName'>): UseRunsResult<TInput, TOutput>;
282
294
  declare function useRuns(options?: UseRunsOptions): UseRunsResult;
283
295
 
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 };
296
+ export { DurablyProvider, type DurablyProviderProps, LogEntry, Progress, RunStatus, TypedRun, type UseJobLogsOptions, type UseJobLogsResult, type UseJobOptions, type UseJobResult, type UseJobRunOptions, type UseJobRunResult, type UseRunsOptions, type UseRunsResult, useDurably, useJob, useJobLogs, useJobRun, useRuns };