Skip to content

Commit ba51881

Browse files
committed
Lint it
1 parent 88032ee commit ba51881

25 files changed

Lines changed: 837 additions & 821 deletions

lib/CloudConvert.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
import axios, { AxiosInstance } from "axios";
1+
import axios, { AxiosInstance } from 'axios';
22
import io from 'socket.io-client';
3-
import JobsResource, { JobEventData } from "./JobsResource";
4-
import TasksResource, { TaskEventData } from "./TasksResource";
5-
import UsersResource from "./UsersResource";
6-
import WebhooksResource from "./WebhooksResource";
3+
import JobsResource, { JobEventData } from './JobsResource';
4+
import TasksResource, { TaskEventData } from './TasksResource';
5+
import UsersResource from './UsersResource';
6+
import WebhooksResource from './WebhooksResource';
77

88
export default class CloudConvert {
99
private socket: SocketIOClient.Socket | undefined;
1010
private subscribedChannels: Map<string, boolean> | undefined;
11-
11+
1212
public readonly apiKey: string;
1313
public readonly useSandbox: boolean;
14-
14+
1515
public axios!: AxiosInstance;
1616
public tasks!: TasksResource;
1717
public jobs!: JobsResource;
1818
public users!: UsersResource;
1919
public webhooks!: WebhooksResource;
2020

2121
constructor(apiKey: string, useSandbox = false) {
22-
2322
this.apiKey = apiKey;
2423
this.useSandbox = useSandbox;
2524

2625
this.createAxiosInstance();
2726
this.createResources();
28-
2927
}
3028

31-
3229
createAxiosInstance(): void {
3330
this.axios = axios.create({
34-
baseURL: this.useSandbox ? 'https://api.sandbox.cloudconvert.com/v2/' : 'https://api.cloudconvert.com/v2/',
31+
baseURL: this.useSandbox
32+
? 'https://api.sandbox.cloudconvert.com/v2/'
33+
: 'https://api.cloudconvert.com/v2/',
3534
headers: {
36-
'Authorization': 'Bearer ' + this.apiKey,
37-
'User-Agent': 'cloudconvert-node/v2 (https://github.com/cloudconvert/cloudconvert-node)'
35+
Authorization: 'Bearer ' + this.apiKey,
36+
'User-Agent':
37+
'cloudconvert-node/v2 (https://github.com/cloudconvert/cloudconvert-node)'
3838
}
3939
});
4040
}
@@ -46,13 +46,22 @@ export default class CloudConvert {
4646
this.webhooks = new WebhooksResource(this);
4747
}
4848

49-
50-
subscribe(channel: string, event: string, callback: ((event: JobEventData) => void) | ((event: TaskEventData) => void)): void {
51-
49+
subscribe(
50+
channel: string,
51+
event: string,
52+
callback:
53+
| ((event: JobEventData) => void)
54+
| ((event: TaskEventData) => void)
55+
): void {
5256
if (!this.socket) {
53-
this.socket = io.connect(this.useSandbox ? 'https://socketio.sandbox.cloudconvert.com' : 'https://socketio.cloudconvert.com', {
54-
transports: ['websocket']
55-
});
57+
this.socket = io.connect(
58+
this.useSandbox
59+
? 'https://socketio.sandbox.cloudconvert.com'
60+
: 'https://socketio.cloudconvert.com',
61+
{
62+
transports: ['websocket']
63+
}
64+
);
5665
this.subscribedChannels = new Map<string, boolean>();
5766
}
5867

@@ -61,23 +70,21 @@ export default class CloudConvert {
6170
channel,
6271
auth: {
6372
headers: {
64-
'Authorization': 'Bearer ' + this.apiKey
73+
Authorization: 'Bearer ' + this.apiKey
6574
}
66-
},
75+
}
6776
});
6877
this.subscribedChannels?.set(channel, true);
6978
}
7079

71-
this.socket.on(event, function (eventChannel: string, eventData: any): void {
80+
this.socket.on(event, function (
81+
eventChannel: string,
82+
eventData: any
83+
): void {
7284
if (channel !== eventChannel) {
7385
return;
7486
}
7587
callback(eventData);
7688
});
77-
7889
}
79-
80-
8190
}
82-
83-

lib/JobsResource.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { Operation, Task, TaskEventData, TaskStatus } from './TasksResource';
33

44
export type JobEvent = 'created' | 'updated' | 'finished' | 'failed';
55
export 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

911
export 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';
1921
interface 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)
77104
type 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
83112
type 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)
87118
type TaskTemplate<O> = TaskExtras<O> & OperationData<O>;
88119
// Given a union type U of operation strings, turn each operation string into its TaskTemplate
89120
type Distribute<U> = U extends any ? TaskTemplate<U> : never;
90121
// Create a union of all possible tasks
91122
type 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

Comments
 (0)