Skip to content

Client

Client<TJobTypeDefinitions, TStateAdapter, TJobId> = object

Defined in: packages/core/src/client.ts:202

The public API for managing chains. Created via createClient.

Methods are split into three categories:

  • Mutating — createChain, createChains, completeChain, deleteChain, deleteChains, rescheduleJob, rescheduleJobs. Require transactionHooks and a transaction context; they throw Error if called without the transaction context from withTransaction.
  • Read-only — getChain, getChains, getJob, getJobs, listChainTypeNames, listJobTypeNames, countByChainTypeNames, countByJobTypeNames, listChains, listJobs, listChainJobs, getJobBlockers, listBlockedJobs. Accept an optional transaction context.
  • Waiting — awaitChain. Takes no transaction context: it polls outside any transaction and listens for notify adapter events.

TJobTypeDefinitions extends BaseJobTypeDefinitions

TStateAdapter extends StateAdapter<any, any>

TJobId = GetStateAdapterJobId<TStateAdapter>

readonly [helpersSymbol]: Helpers

Defined in: packages/core/src/client.ts:207


awaitChain: <TChainTypeName>(chain, options) => Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> & object>

Defined in: packages/core/src/client.ts:221

Wait for a chain to complete. Combines polling with notify adapter events.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

TJobId

TChainTypeName

number

AbortSignal

number

Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> & object>

WaitChainTimeoutError on timeout or abort.

ChainNotFoundError if the chain disappears or never existed.

ChainTypeMismatchError if typeName is provided and does not match.


completeChain: <TChainTypeName, THandler, TResult>(options) => Promise<TResult>

Defined in: packages/core/src/client.ts:370

Complete a chain from outside a worker. Validates typeName, then passes the current job and a completeJob function to the handler. The handler may decline (return without calling completeJob); when it does complete, the callback passes exactly one outcome — { output } or { continueWith: {...} } — to finish, which writes it before it returns.

completeJob resolves to the continuation when the outcome continued the chain, so several jobs can be walked in a row:

job = await completeJob(job, async ({ finish }) =>
finish({ continueWith: { typeName: "step-a", input: { valueA: 42 } } }));

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions>

THandler extends (…args) => Promise<any> = ChainHandler<TStateAdapter, TJobTypeDefinitions, TChainTypeName>

TResult = CompleteChainResultFromHandler<TJobId, TJobTypeDefinitions, TChainTypeName, THandler>

object & GetStateAdapterTxContext<TStateAdapter>

Promise<TResult>

ChainNotFoundError if the chain does not exist.

ChainTypeMismatchError if the chain’s type does not match typeName.

JobAlreadyCompletedError from the inner completeJob if the job is already completed.

BlockerLimitExceededError from the inner finish if a continueWith outcome declares more blockers than the per-job limit.


countByChainTypeNames: (options) => Promise<object[]>

Defined in: packages/core/src/client.ts:474

Returns capped per-status counts for the given chain type names, in input order.

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<object[]>


countByJobTypeNames: (options) => Promise<object[]>

Defined in: packages/core/src/client.ts:488

Returns capped per-status counts for the given job type names, in input order.

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<object[]>


createChain: <TChainTypeName>(options) => Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> & object>

Defined in: packages/core/src/client.ts:253

Create a new chain. Returns the created chain with a deduplicated flag. Pass id to assign a caller-supplied ID for the root job; if the chain is deduplicated, the returned chain carries the existing row’s ID, not the caller’s.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions>

CreateChainEntry<TJobId, TJobTypeDefinitions, TChainTypeName> & object & GetStateAdapterTxContext<TStateAdapter>

Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> & object>

InvalidJobIdError if id fails the state adapter’s validateId check.

BlockerLimitExceededError if the root job declares more blockers than the per-job limit.

ChainNotFoundError if a blocker chain does not exist.

JobTypeValidationError if the job type rejects the entry, input, or blockers.

TypeError if deduplication.scope is missing or not "running" / "any".

The state adapter’s own error (e.g. a unique-constraint violation) if a caller-supplied id is already taken.


createChains: <TChains>(options) => Promise<CreateChainsResult<TJobId, TJobTypeDefinitions, TChains>>

Defined in: packages/core/src/client.ts:275

Create multiple chains in a single batch operation. Returns created chains with deduplicated flags, in the same order as input. Each item may carry an optional id; dedup wins over a caller-supplied id when applicable.

TChains extends readonly AnyCreateChainEntry<TJobId, TJobTypeDefinitions>[]

object & GetStateAdapterTxContext<TStateAdapter>

Promise<CreateChainsResult<TJobId, TJobTypeDefinitions, TChains>>

InvalidJobIdError if any id fails the state adapter’s validateId check.

BlockerLimitExceededError if any root job declares more blockers than the per-job limit.

ChainNotFoundError if any blocker chain does not exist.

JobTypeValidationError if a job type rejects an item’s entry, input, or blockers.

TypeError if deduplication.scope is missing or not "running" / "any".

The state adapter’s own error (e.g. a unique-constraint violation) if a caller-supplied id is already taken.


deleteChain: <TEntryName>(options) => Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TEntryName> | undefined>

Defined in: packages/core/src/client.ts:288

Delete a single chain by ID. Returns the deleted chain, or undefined if no chain with that ID exists.

TEntryName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

object & GetStateAdapterTxContext<TStateAdapter>

Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TEntryName> | undefined>

BlockerReferenceError if external jobs depend on it.


deleteChains: <TEntryName>(options) => Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TEntryName>[]>

Defined in: packages/core/src/client.ts:303

Delete chains by ID. Missing IDs are silently skipped.

TEntryName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

object & GetStateAdapterTxContext<TStateAdapter>

Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TEntryName>[]>

BlockerReferenceError if external jobs depend on them.


getChain: <TChainTypeName>(options) => Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> | undefined>

Defined in: packages/core/src/client.ts:393

Get a single chain by ID. Pass typeName for type narrowing.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> | undefined>

ChainTypeMismatchError if typeName is provided and does not match.


getChains: <TChainTypeName>(options) => Promise<(ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> | undefined)[]>

Defined in: packages/core/src/client.ts:411

Get multiple chains by ID. Returns a positional array aligned with the input ids — undefined for any ID that does not exist. Pass typeName to narrow the return type; all found chains must match or ChainTypeMismatchError is thrown.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<(ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName> | undefined)[]>

ChainTypeMismatchError if typeName is provided and any found chain does not match.


getJob: <TJobTypeName>(options) => Promise<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName> | undefined>

Defined in: packages/core/src/client.ts:426

Get a single job by ID. Pass typeName for type narrowing.

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName> | undefined>

JobTypeMismatchError if typeName is provided and does not match.


getJobBlockers: <TJobTypeName, TBlockers>(options) => Promise<TBlockers>

Defined in: packages/core/src/client.ts:575

Get the blocker chains for a specific job. Not paginated — blockers are bounded by design. Pass typeName for type narrowing.

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

TBlockers extends readonly unknown[] = BlockerChains<TJobId, TJobTypeDefinitions, TJobTypeName>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<TBlockers>

JobTypeMismatchError if typeName is provided and does not match.


getJobs: <TJobTypeName>(options) => Promise<(ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName> | undefined)[]>

Defined in: packages/core/src/client.ts:443

Get multiple jobs by ID. Returns a positional array aligned with the input ids — undefined for any ID that does not exist. Pass typeName to narrow the return type; all found jobs must match or JobTypeMismatchError is thrown.

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<(ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName> | undefined)[]>

JobTypeMismatchError if typeName is provided and any found job does not match.


listBlockedJobs: <TChainTypeName, TBlockedJob>(options) => Promise<Page<TBlockedJob>>

Defined in: packages/core/src/client.ts:592

List jobs from other chains that are blocked by a given chain. Useful for understanding downstream impact before deletion. Pass typeName for type narrowing.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

TBlockedJob = ResolvedJob<TJobId, TJobTypeDefinitions, JobTypeBlockedNames<TJobTypeDefinitions, TChainTypeName> & JobTypeNames<TJobTypeDefinitions>>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<Page<TBlockedJob>>

ChainTypeMismatchError if typeName is provided and does not match.


listChainJobs: <TChainTypeName>(options) => Promise<Page<ResolvedChainJobs<TJobId, TJobTypeDefinitions, TChainTypeName>>>

Defined in: packages/core/src/client.ts:556

List jobs within a specific chain, in chain order. Defaults to ascending order. Pass chainTypeName for type narrowing.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

object & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<Page<ResolvedChainJobs<TJobId, TJobTypeDefinitions, TChainTypeName>>>

ChainTypeMismatchError if chainTypeName is provided and does not match.


listChains: <TChainTypeName>(options) => Promise<Page<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName>>>

Defined in: packages/core/src/client.ts:505

List chains with filtering and cursor-based pagination. Defaults to orderDirection: "desc", limit: 50, and orderBy: "completedAt" when status is "completed", "createdAt" otherwise.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

object & { orderBy?: "createdAt"; status?: undefined; } | { orderBy?: "createdAt"; status: "running"; } | { orderBy?: "createdAt" | "completedAt"; status: "completed"; } & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<Page<ResolvedChain<TJobId, TJobTypeDefinitions, TChainTypeName>>>


listChainTypeNames: <TChainTypeName>(options?) => Promise<TChainTypeName[]>

Defined in: packages/core/src/client.ts:455

Returns distinct chain type names present in the data, sorted alphabetically.

TChainTypeName extends JobTypeEntryNames<TJobTypeDefinitions> = JobTypeEntryNames<TJobTypeDefinitions>

Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<TChainTypeName[]>


listJobs: <TJobTypeName>(options) => Promise<Page<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName>>>

Defined in: packages/core/src/client.ts:530

List jobs with filtering and cursor-based pagination. Defaults to orderDirection: "desc", limit: 50, and an orderBy that follows status: scheduledAt for blocked/pending, attemptAt for running, completedAt for completed, createdAt when unfiltered.

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

object & { orderBy?: "createdAt"; status?: undefined; } | { orderBy?: "createdAt" | "scheduledAt"; status: "blocked"; } | { orderBy?: "createdAt" | "scheduledAt"; status: "pending"; } | { orderBy?: "createdAt" | "attemptAt" | "attemptUntil"; status: "running"; } | { orderBy?: "createdAt" | "completedAt"; status: "completed"; } & Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<Page<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName>>>


listJobTypeNames: <TJobTypeName>(options?) => Promise<TJobTypeName[]>

Defined in: packages/core/src/client.ts:465

Returns distinct job type names present in the data, sorted alphabetically.

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

Partial<GetStateAdapterTxContext<TStateAdapter>>

Promise<TJobTypeName[]>


rescheduleJob: <TJobTypeName>(options) => Promise<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName>>

Defined in: packages/core/src/client.ts:321

Reschedule a pending job by setting its scheduledAt from the optional schedule ({ at } | { afterMs }); omitting schedule reschedules to now. Past times clamp to now.

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

object & GetStateAdapterTxContext<TStateAdapter>

Promise<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName>>

JobNotFoundError if the job does not exist.

JobNotReschedulableError if the job is not pending.


rescheduleJobs: <TJobTypeName>(options) => Promise<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName>[]>

Defined in: packages/core/src/client.ts:340

Reschedule multiple pending jobs, setting each scheduledAt from the optional schedule (omitted = now, past times clamped to now). Validation is atomic — no job is rescheduled on failure. Returns jobs in input order. Empty ids returns [].

TJobTypeName extends JobTypeNames<TJobTypeDefinitions> = JobTypeNames<TJobTypeDefinitions>

object & GetStateAdapterTxContext<TStateAdapter>

Promise<ResolvedJob<TJobId, TJobTypeDefinitions, TJobTypeName>[]>

JobsNotFoundError (batch variant listing every offending id) if any input is missing.

JobsNotReschedulableError (batch variant listing every offending id) if any input is not pending.