@sidequest/core
Version:
@sidequest/core is the core package of SideQuest, a distributed background job queue for Node.js and TypeScript applications.
73 lines (70 loc) • 2.03 kB
TypeScript
import { ErrorData } from '../schema/error-data.js';
import { CompleteTransition } from './complete-transition.js';
import { FailTransition } from './fail-transition.js';
import { RetryTransition } from './retry-transition.js';
import { SnoozeTransition } from './snooze-transition.js';
/**
* Possible job result types.
*/
type JobResultType = "retry" | "completed" | "failed" | "snooze";
/**
* Base interface for job result objects.
*/
interface BaseResult {
/** Marker for job transition objects. */
__is_job_transition__: true;
/** The type of job result. */
type: JobResultType;
}
/**
* Result for a retry transition.
*/
type RetryResult = BaseResult & {
type: "retry";
delay?: number;
error: ErrorData;
};
/**
* Result for a failed transition.
*/
type FailedResult = BaseResult & {
type: "failed";
error: ErrorData;
};
/**
* Result for a completed transition.
*/
type CompletedResult = BaseResult & {
type: "completed";
result: unknown;
};
/**
* Result for a snooze transition.
*/
type SnoozeResult = BaseResult & {
type: "snooze";
delay: number;
};
/**
* Union type for all job results.
*/
type JobResult = RetryResult | FailedResult | CompletedResult | SnoozeResult;
/**
* Factory for creating job transitions from job results.
*/
declare class JobTransitionFactory {
/**
* Creates a job transition instance from a job result.
* @param jobResult The job result object.
* @returns The corresponding job transition instance.
*/
static create(jobResult: JobResult): FailTransition | CompleteTransition | RetryTransition | SnoozeTransition;
}
/**
* Checks if a value is a JobResult object. If this returns false, it is probably a raw job result.
* @param value The value to check.
* @returns True if the value is a JobResult.
*/
declare function isJobResult(value: unknown): value is JobResult;
export { JobTransitionFactory, isJobResult };
export type { CompletedResult, FailedResult, JobResult, RetryResult, SnoozeResult };