UNPKG

@nosana/kit

Version:

Nosana KIT

198 lines 6.03 kB
import { type ConvertTypesForDb } from '../../../utils/index.js'; import type { Address } from '@solana/kit'; import type { ProgramDeps } from '../../../types.js'; import type { ProgramConfig } from '../../../config/types.js'; import * as Instructions from './instructions/index.js'; import * as programClient from '@nosana/jobs-program'; import type { SimpleMonitorEvent, MonitorEvent } from './monitor/index.js'; export declare enum JobState { QUEUED = 0, RUNNING = 1, COMPLETED = 2, STOPPED = 3 } export declare enum MarketQueueType { JOB_QUEUE = 0, NODE_QUEUE = 1 } export type Job = Omit<ConvertTypesForDb<programClient.JobAccountArgs>, 'state'> & { address: Address; state: JobState; }; export type Market = Omit<ConvertTypesForDb<programClient.MarketAccountArgs>, 'queueType'> & { address: Address; queueType: MarketQueueType; }; export type Run = ConvertTypesForDb<programClient.RunAccountArgs> & { address: Address; }; export { MonitorEventType } from './monitor/index.js'; export type { SimpleMonitorEvent, MonitorEvent } from './monitor/index.js'; export type PostParams = Instructions.ListParams | Instructions.AssignParams; export type PostInstruction = Instructions.ListInstruction | Instructions.AssignInstruction; /** * Jobs program interface * @group @nosana/kit */ export interface JobsProgram { /** * Fetch a job account by address */ get(addr: Address, checkRun?: boolean): Promise<Job>; /** * Fetch a run account by address */ run(addr: Address): Promise<Run>; /** * Fetch a market account by address */ market(addr: Address): Promise<Market>; /** * Fetch multiple job accounts by address */ multiple(addresses: Address[], checkRuns?: boolean): Promise<Job[]>; /** * Fetch all job accounts */ all(filters?: { state?: JobState; market?: Address; node?: Address; project?: Address; }, checkRuns?: boolean): Promise<Job[]>; /** * Fetch all run accounts */ runs(filters?: { node?: Address; job?: Address; }): Promise<Run[]>; /** * Fetch all market accounts */ markets(): Promise<Market[]>; /** * List a new job to the marketplace */ list: Instructions.List; /** * Post a new job to the marketplace (can list or assign based on params) */ post(params: Instructions.ListParams | Instructions.AssignParams): Promise<Instructions.ListInstruction | Instructions.AssignInstruction>; /** * Assign a job directly to a host node */ assign: Instructions.Assign; /** * Extend an existing job's timeout */ extend: Instructions.Extend; /** * Delist a job from the marketplace */ delist: Instructions.Delist; /** * Create a new market */ open(params?: Instructions.OpenParams): Promise<Instructions.OpenInstruction>; /** * Create a new market (synonym for open) */ createMarket(params?: Instructions.OpenParams): Promise<Instructions.OpenInstruction>; /** * Close a market */ close: Instructions.Close; /** * Close a market (synonym for close) */ closeMarket: Instructions.Close; /** * Stop a running job */ end: Instructions.End; /** * Enters the MarketAccount queue, or create a RunAccount. */ work: Instructions.Work; /** * Complete a job that has been stopped. */ finish: Instructions.Finish; /** * Post the result for a JobAccount to finish it and get paid. */ complete: Instructions.Complete; /** * Quit a JobAccount that you have started. */ quit: Instructions.Quit; /** * Exit the node queue */ stop: Instructions.Stop; /** * Monitor program account updates using async iterators. * Automatically merges run account data into job account updates. * Returns a tuple of [eventStream, stopFunction]. * * @example * ```typescript * const [eventStream, stop] = await jobsProgram.monitor(); * for await (const event of eventStream) { * if (event.type === MonitorEventType.JOB) { * console.log('Job updated:', event.data.address); * } else if (event.type === MonitorEventType.MARKET) { * console.log('Market updated:', event.data.address); * } * } * ``` */ monitor(): Promise<[AsyncIterable<SimpleMonitorEvent>, () => void]>; /** * Monitor program account updates with detailed events for each account type. * Provides separate events for job, market, and run accounts. * Returns a tuple of [eventStream, stopFunction]. * * @example * ```typescript * const [eventStream, stop] = await jobsProgram.monitorDetailed(); * for await (const event of eventStream) { * switch (event.type) { * case MonitorEventType.JOB: * console.log('Job updated:', event.data.address); * break; * case MonitorEventType.MARKET: * console.log('Market updated:', event.data.address); * break; * case MonitorEventType.RUN: * console.log('Run updated:', event.data.address); * break; * } * } * ``` */ monitorDetailed(): Promise<[AsyncIterable<MonitorEvent>, () => void]>; } /** * Creates a new JobsProgram instance. * * @param deps - Program dependencies (config, logger, solana service, wallet getter) * @returns A JobsProgram instance with methods to interact with the jobs program * * @example * ```ts * import { createJobsProgram } from '@nosana/kit'; * * const jobsProgram = createJobsProgram({ * config, * logger, * solana, * getWallet, * }); * * const job = await jobsProgram.get('job-address'); * ``` */ export declare function createJobsProgram(deps: ProgramDeps, config: ProgramConfig): JobsProgram; //# sourceMappingURL=JobsProgram.d.ts.map