@@ -3,8 +3,10 @@ import { Operation, Task, TaskEventData, TaskStatus } from './TasksResource';
33
44export type JobEvent = 'created' | 'updated' | 'finished' | 'failed' ;
55export type JobStatus = 'processing' | 'finished' | 'error' ;
6- export type JobTaskStatus = Task [ 'status' ] | 'queued'
7- export interface JobEventData { job : Job }
6+ export type JobTaskStatus = Task [ 'status' ] | 'queued' ;
7+ export interface JobEventData {
8+ job : Job ;
9+ }
810
911export interface Job {
1012 id : string ;
@@ -15,7 +17,7 @@ export interface Job {
1517 ended_at : string | null ;
1618 tasks : JobTask [ ] ;
1719}
18- type NotPresentWhenInsideJob = 'job_id' | 'status'
20+ type NotPresentWhenInsideJob = 'job_id' | 'status' ;
1921interface JobTask extends Omit < Task , NotPresentWhenInsideJob > {
2022 name : string ;
2123 status : JobTaskStatus ;
@@ -36,11 +38,21 @@ export default class JobsResource {
3638 }
3739
3840 async wait ( id : string ) : Promise < Job > {
39- const response = await this . cloudConvert . axios . get ( 'jobs/' + id + '/wait' ) ;
41+ const response = await this . cloudConvert . axios . get (
42+ 'jobs/' + id + '/wait'
43+ ) ;
4044 return response . data . data ;
4145 }
4246
43- async all ( query : { 'filter[status]' ?: JobStatus ; 'filter[tag]' ?: string ; include ?: string ; per_page ?: number ; page ?: number ; } | null = null ) : Promise < Job [ ] > {
47+ async all (
48+ query : {
49+ 'filter[status]' ?: JobStatus ;
50+ 'filter[tag]' ?: string ;
51+ include ?: string ;
52+ per_page ?: number ;
53+ page ?: number ;
54+ } | null = null
55+ ) : Promise < Job [ ] > {
4456 const response = await this . cloudConvert . axios . get ( 'jobs' , {
4557 params : query || { }
4658 } ) ;
@@ -57,14 +69,29 @@ export default class JobsResource {
5769 await this . cloudConvert . axios . delete ( 'jobs/' + id ) ;
5870 }
5971
60- async subscribeEvent ( id : string , event : string , callback : ( event : JobEventData ) => void ) : Promise < void > {
61- this . cloudConvert . subscribe ( 'private-job.' + id , 'job.' + event , callback ) ;
72+ async subscribeEvent (
73+ id : string ,
74+ event : string ,
75+ callback : ( event : JobEventData ) => void
76+ ) : Promise < void > {
77+ this . cloudConvert . subscribe (
78+ 'private-job.' + id ,
79+ 'job.' + event ,
80+ callback
81+ ) ;
6282 }
6383
64- async subscribeTaskEvent ( id : string , event : string , callback : ( event : TaskEventData ) => void ) : Promise < void > {
65- this . cloudConvert . subscribe ( 'private-job.' + id + '.tasks' , 'task.' + event , callback ) ;
84+ async subscribeTaskEvent (
85+ id : string ,
86+ event : string ,
87+ callback : ( event : TaskEventData ) => void
88+ ) : Promise < void > {
89+ this . cloudConvert . subscribe (
90+ 'private-job.' + id + '.tasks' ,
91+ 'task.' + event ,
92+ callback
93+ ) ;
6694 }
67-
6895}
6996
7097// We need to map the types from the large Operation union type
@@ -76,20 +103,29 @@ export default class JobsResource {
76103// All possible operation strings ("import/url" etc)
77104type PossibleOperationStrings = Operation [ 'operation' ] ;
78105// Every argument in the tasks object should be assignable to this (for some operation string O)
79- interface NamedOperation < O > { operation : O }
106+ interface NamedOperation < O > {
107+ operation : O ;
108+ }
80109// Given an operation string O, get the operation for it
81- type OperationByName < O > = Extract < Operation , NamedOperation < O > >
110+ type OperationByName < O > = Extract < Operation , NamedOperation < O > > ;
82111// Given an operation string O, get the operation data for it
83112type OperationData < O > = OperationByName < O > [ 'data' ] ;
84113// Add all properties to task that can only occur in tasks that are inside jobs
85- interface TaskExtras < O > extends NamedOperation < O > { ignore_error ?: boolean ; }
114+ interface TaskExtras < O > extends NamedOperation < O > {
115+ ignore_error ?: boolean ;
116+ }
86117// Every argument in the tasks object is typed by this (for some operation string O)
87118type TaskTemplate < O > = TaskExtras < O > & OperationData < O > ;
88119// Given a union type U of operation strings, turn each operation string into its TaskTemplate
89120type Distribute < U > = U extends any ? TaskTemplate < U > : never ;
90121// Create a union of all possible tasks
91122type PossibleOperations = Distribute < PossibleOperationStrings > ;
92123// Allow any number of names, each typed by a possible operation
93- interface TaskContainer { [ name : string ] : PossibleOperations ; }
124+ interface TaskContainer {
125+ [ name : string ] : PossibleOperations ;
126+ }
94127// Add the other properties that are required for job creation
95- interface JobTemplate { tasks : TaskContainer ; tag ?: string ; }
128+ interface JobTemplate {
129+ tasks : TaskContainer ;
130+ tag ?: string ;
131+ }
0 commit comments