import { isString , JobConfig , TSError } from '@terascope/job-components' ; import autoBind from 'auto-bind' ; import Client from './client' ; import Job from './job' ; import { ClientConfig , JobConfiguration , SearchOptions , JobSearchParams , JobListStatusQuery , JobIDResponse } from './interfaces' ; export default class Jobs extends Client { constructor ( config ) { super ( config ) ; autoBind ( this ) ; } async submit ( jobSpec , shouldNotStart ? ) { if ( ! jobSpec ) { throw new TSError ( 'Submit requires a jobSpec' , { statusCode : 400 } ) ; } const job = await this . post ( '/jobs' , jobSpec , { searchParams : { start : ! shouldNotStart } } ) ; return this . wrap ( job . job_id ) ; } async list ( status ? , searchOptions = { } ) { const query = _parseListOptions ( status ) ; return this . get ( '/jobs' , this . makeOptions ( query , searchOptions ) ) ; } /**
     * Wraps the job_id with convenience functions for accessing
     * the state on the server.
    */ wrap ( jobId ) { return new Job ( this . _config , jobId ) ; } } function _parseListOptions ( options ? ) { if ( ! options ) return { status : '*' } ; if ( isString ( options ) ) return { status : options } ; return options ; }