Skip to content

Commit d999000

Browse files
Merge branch 'feature/frontend-uploader' of https://github.com/monicasmith463/study-assistant into feature/frontend-uploader
2 parents 9e3d2a5 + 963c3b7 commit d999000

9 files changed

Lines changed: 390 additions & 390 deletions

File tree

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import type { ApiRequestOptions } from "./ApiRequestOptions";
2-
import type { ApiResult } from "./ApiResult";
1+
import type { ApiRequestOptions } from "./ApiRequestOptions"
2+
import type { ApiResult } from "./ApiResult"
33

44
export class ApiError extends Error {
5-
public readonly url: string;
6-
public readonly status: number;
7-
public readonly statusText: string;
8-
public readonly body: unknown;
9-
public readonly request: ApiRequestOptions;
5+
public readonly url: string
6+
public readonly status: number
7+
public readonly statusText: string
8+
public readonly body: unknown
9+
public readonly request: ApiRequestOptions
1010

1111
constructor(
1212
request: ApiRequestOptions,
1313
response: ApiResult,
1414
message: string,
1515
) {
16-
super(message);
16+
super(message)
1717

18-
this.name = "ApiError";
19-
this.url = response.url;
20-
this.status = response.status;
21-
this.statusText = response.statusText;
22-
this.body = response.body;
23-
this.request = request;
18+
this.name = "ApiError"
19+
this.url = response.url
20+
this.status = response.status
21+
this.statusText = response.statusText
22+
this.body = response.body
23+
this.request = request
2424
}
2525
}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
export type ApiRequestOptions<T = unknown> = {
2-
readonly body?: any;
3-
readonly cookies?: Record<string, unknown>;
4-
readonly errors?: Record<number | string, string>;
5-
readonly formData?: Record<string, unknown> | any[] | Blob | File;
6-
readonly headers?: Record<string, unknown>;
7-
readonly mediaType?: string;
2+
readonly body?: any
3+
readonly cookies?: Record<string, unknown>
4+
readonly errors?: Record<number | string, string>
5+
readonly formData?: Record<string, unknown> | any[] | Blob | File
6+
readonly headers?: Record<string, unknown>
7+
readonly mediaType?: string
88
readonly method:
99
| "DELETE"
1010
| "GET"
1111
| "HEAD"
1212
| "OPTIONS"
1313
| "PATCH"
1414
| "POST"
15-
| "PUT";
16-
readonly path?: Record<string, unknown>;
17-
readonly query?: Record<string, unknown>;
18-
readonly responseHeader?: string;
19-
readonly responseTransformer?: (data: unknown) => Promise<T>;
20-
readonly url: string;
21-
};
15+
| "PUT"
16+
readonly path?: Record<string, unknown>
17+
readonly query?: Record<string, unknown>
18+
readonly responseHeader?: string
19+
readonly responseTransformer?: (data: unknown) => Promise<T>
20+
readonly url: string
21+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type ApiResult<TData = any> = {
2-
readonly body: TData;
3-
readonly ok: boolean;
4-
readonly status: number;
5-
readonly statusText: string;
6-
readonly url: string;
7-
};
2+
readonly body: TData
3+
readonly ok: boolean
4+
readonly status: number
5+
readonly statusText: string
6+
readonly url: string
7+
}
Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
export class CancelError extends Error {
22
constructor(message: string) {
3-
super(message);
4-
this.name = "CancelError";
3+
super(message)
4+
this.name = "CancelError"
55
}
66

77
public get isCancelled(): boolean {
8-
return true;
8+
return true
99
}
1010
}
1111

1212
export interface OnCancel {
13-
readonly isResolved: boolean;
14-
readonly isRejected: boolean;
15-
readonly isCancelled: boolean;
13+
readonly isResolved: boolean
14+
readonly isRejected: boolean
15+
readonly isCancelled: boolean
1616

17-
(cancelHandler: () => void): void;
17+
(cancelHandler: () => void): void
1818
}
1919

2020
export class CancelablePromise<T> implements Promise<T> {
21-
private _isResolved: boolean;
22-
private _isRejected: boolean;
23-
private _isCancelled: boolean;
24-
readonly cancelHandlers: (() => void)[];
25-
readonly promise: Promise<T>;
26-
private _resolve?: (value: T | PromiseLike<T>) => void;
27-
private _reject?: (reason?: unknown) => void;
21+
private _isResolved: boolean
22+
private _isRejected: boolean
23+
private _isCancelled: boolean
24+
readonly cancelHandlers: (() => void)[]
25+
readonly promise: Promise<T>
26+
private _resolve?: (value: T | PromiseLike<T>) => void
27+
private _reject?: (reason?: unknown) => void
2828

2929
constructor(
3030
executor: (
@@ -33,94 +33,94 @@ export class CancelablePromise<T> implements Promise<T> {
3333
onCancel: OnCancel,
3434
) => void,
3535
) {
36-
this._isResolved = false;
37-
this._isRejected = false;
38-
this._isCancelled = false;
39-
this.cancelHandlers = [];
36+
this._isResolved = false
37+
this._isRejected = false
38+
this._isCancelled = false
39+
this.cancelHandlers = []
4040
this.promise = new Promise<T>((resolve, reject) => {
41-
this._resolve = resolve;
42-
this._reject = reject;
41+
this._resolve = resolve
42+
this._reject = reject
4343

4444
const onResolve = (value: T | PromiseLike<T>): void => {
4545
if (this._isResolved || this._isRejected || this._isCancelled) {
46-
return;
46+
return
4747
}
48-
this._isResolved = true;
49-
if (this._resolve) this._resolve(value);
50-
};
48+
this._isResolved = true
49+
if (this._resolve) this._resolve(value)
50+
}
5151

5252
const onReject = (reason?: unknown): void => {
5353
if (this._isResolved || this._isRejected || this._isCancelled) {
54-
return;
54+
return
5555
}
56-
this._isRejected = true;
57-
if (this._reject) this._reject(reason);
58-
};
56+
this._isRejected = true
57+
if (this._reject) this._reject(reason)
58+
}
5959

6060
const onCancel = (cancelHandler: () => void): void => {
6161
if (this._isResolved || this._isRejected || this._isCancelled) {
62-
return;
62+
return
6363
}
64-
this.cancelHandlers.push(cancelHandler);
65-
};
64+
this.cancelHandlers.push(cancelHandler)
65+
}
6666

6767
Object.defineProperty(onCancel, "isResolved", {
6868
get: (): boolean => this._isResolved,
69-
});
69+
})
7070

7171
Object.defineProperty(onCancel, "isRejected", {
7272
get: (): boolean => this._isRejected,
73-
});
73+
})
7474

7575
Object.defineProperty(onCancel, "isCancelled", {
7676
get: (): boolean => this._isCancelled,
77-
});
77+
})
7878

79-
return executor(onResolve, onReject, onCancel as OnCancel);
80-
});
79+
return executor(onResolve, onReject, onCancel as OnCancel)
80+
})
8181
}
8282

8383
get [Symbol.toStringTag]() {
84-
return "Cancellable Promise";
84+
return "Cancellable Promise"
8585
}
8686

8787
public then<TResult1 = T, TResult2 = never>(
8888
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
8989
onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,
9090
): Promise<TResult1 | TResult2> {
91-
return this.promise.then(onFulfilled, onRejected);
91+
return this.promise.then(onFulfilled, onRejected)
9292
}
9393

9494
public catch<TResult = never>(
9595
onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null,
9696
): Promise<T | TResult> {
97-
return this.promise.catch(onRejected);
97+
return this.promise.catch(onRejected)
9898
}
9999

100100
public finally(onFinally?: (() => void) | null): Promise<T> {
101-
return this.promise.finally(onFinally);
101+
return this.promise.finally(onFinally)
102102
}
103103

104104
public cancel(): void {
105105
if (this._isResolved || this._isRejected || this._isCancelled) {
106-
return;
106+
return
107107
}
108-
this._isCancelled = true;
108+
this._isCancelled = true
109109
if (this.cancelHandlers.length) {
110110
try {
111111
for (const cancelHandler of this.cancelHandlers) {
112-
cancelHandler();
112+
cancelHandler()
113113
}
114114
} catch (error) {
115-
console.warn("Cancellation threw an error", error);
116-
return;
115+
console.warn("Cancellation threw an error", error)
116+
return
117117
}
118118
}
119-
this.cancelHandlers.length = 0;
120-
if (this._reject) this._reject(new CancelError("Request aborted"));
119+
this.cancelHandlers.length = 0
120+
if (this._reject) this._reject(new CancelError("Request aborted"))
121121
}
122122

123123
public get isCancelled(): boolean {
124-
return this._isCancelled;
124+
return this._isCancelled
125125
}
126126
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import type { AxiosRequestConfig, AxiosResponse } from "axios";
2-
import type { ApiRequestOptions } from "./ApiRequestOptions";
1+
import type { AxiosRequestConfig, AxiosResponse } from "axios"
2+
import type { ApiRequestOptions } from "./ApiRequestOptions"
33

4-
type Headers = Record<string, string>;
5-
type Middleware<T> = (value: T) => T | Promise<T>;
6-
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>;
4+
type Headers = Record<string, string>
5+
type Middleware<T> = (value: T) => T | Promise<T>
6+
type Resolver<T> = (options: ApiRequestOptions<T>) => Promise<T>
77

88
export class Interceptors<T> {
9-
_fns: Middleware<T>[];
9+
_fns: Middleware<T>[]
1010

1111
constructor() {
12-
this._fns = [];
12+
this._fns = []
1313
}
1414

1515
eject(fn: Middleware<T>): void {
16-
const index = this._fns.indexOf(fn);
16+
const index = this._fns.indexOf(fn)
1717
if (index !== -1) {
18-
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
18+
this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)]
1919
}
2020
}
2121

2222
use(fn: Middleware<T>): void {
23-
this._fns = [...this._fns, fn];
23+
this._fns = [...this._fns, fn]
2424
}
2525
}
2626

2727
export type OpenAPIConfig = {
28-
BASE: string;
29-
CREDENTIALS: "include" | "omit" | "same-origin";
30-
ENCODE_PATH?: ((path: string) => string) | undefined;
31-
HEADERS?: Headers | Resolver<Headers> | undefined;
32-
PASSWORD?: string | Resolver<string> | undefined;
33-
TOKEN?: string | Resolver<string> | undefined;
34-
USERNAME?: string | Resolver<string> | undefined;
35-
VERSION: string;
36-
WITH_CREDENTIALS: boolean;
28+
BASE: string
29+
CREDENTIALS: "include" | "omit" | "same-origin"
30+
ENCODE_PATH?: ((path: string) => string) | undefined
31+
HEADERS?: Headers | Resolver<Headers> | undefined
32+
PASSWORD?: string | Resolver<string> | undefined
33+
TOKEN?: string | Resolver<string> | undefined
34+
USERNAME?: string | Resolver<string> | undefined
35+
VERSION: string
36+
WITH_CREDENTIALS: boolean
3737
interceptors: {
38-
request: Interceptors<AxiosRequestConfig>;
39-
response: Interceptors<AxiosResponse>;
40-
};
41-
};
38+
request: Interceptors<AxiosRequestConfig>
39+
response: Interceptors<AxiosResponse>
40+
}
41+
}
4242

4343
export const OpenAPI: OpenAPIConfig = {
4444
BASE: "",
@@ -54,4 +54,4 @@ export const OpenAPI: OpenAPIConfig = {
5454
request: new Interceptors(),
5555
response: new Interceptors(),
5656
},
57-
};
57+
}

0 commit comments

Comments
 (0)