Skip to content

Commit 6f2a714

Browse files
committed
- Working on formatter for spacing
1 parent ad854a9 commit 6f2a714

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+891
-874
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ trim_trailing_whitespace = true
77
insert_final_newline = true
88
indent_style = space
99
indent_size = 4
10+
11+
[*.hbs]
12+
indent_style = tab

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
dist
2+
samples
23
test/generated
34
test/e2e/generated
45
node_modules

src/templates/core/ApiError.hbs

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
import type { ApiResult } from './ApiResult';
44

55
export class ApiError extends Error {
6-
public readonly url: string;
7-
public readonly status: number;
8-
public readonly statusText: string;
9-
public readonly body: any;
6+
public readonly url: string;
7+
public readonly status: number;
8+
public readonly statusText: string;
9+
public readonly body: any;
1010

11-
constructor(response: ApiResult, message: string) {
12-
super(message);
11+
constructor(response: ApiResult, message: string) {
12+
super(message);
1313

14-
this.name = 'ApiError';
15-
this.url = response.url;
16-
this.status = response.status;
17-
this.statusText = response.statusText;
18-
this.body = response.body;
19-
}
14+
this.name = 'ApiError';
15+
this.url = response.url;
16+
this.status = response.status;
17+
this.statusText = response.statusText;
18+
this.body = response.body;
19+
}
2020
}
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{{>header}}
22

33
export type ApiRequestOptions = {
4-
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
5-
readonly path: string;
6-
readonly cookies?: Record<string, any>;
7-
readonly headers?: Record<string, any>;
8-
readonly query?: Record<string, any>;
9-
readonly formData?: Record<string, any>;
10-
readonly body?: any;
11-
readonly mediaType?: string;
12-
readonly responseHeader?: string;
13-
readonly errors?: Record<number, string>;
4+
readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
5+
readonly path: string;
6+
readonly cookies?: Record<string, any>;
7+
readonly headers?: Record<string, any>;
8+
readonly query?: Record<string, any>;
9+
readonly formData?: Record<string, any>;
10+
readonly body?: any;
11+
readonly mediaType?: string;
12+
readonly responseHeader?: string;
13+
readonly errors?: Record<number, string>;
1414
};

src/templates/core/ApiResult.hbs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{{>header}}
22

33
export type ApiResult = {
4-
readonly url: string;
5-
readonly ok: boolean;
6-
readonly status: number;
7-
readonly statusText: string;
8-
readonly body: any;
4+
readonly url: string;
5+
readonly ok: boolean;
6+
readonly status: number;
7+
readonly statusText: string;
8+
readonly body: any;
99
};

src/templates/core/CancelablePromise.hbs

+115-115
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,126 @@
22

33
export class CancelError extends Error {
44

5-
constructor(message: string) {
6-
super(message);
7-
this.name = 'CancelError';
8-
}
9-
10-
public get isCancelled(): boolean {
11-
return true;
12-
}
5+
constructor(message: string) {
6+
super(message);
7+
this.name = 'CancelError';
8+
}
9+
10+
public get isCancelled(): boolean {
11+
return true;
12+
}
1313
}
1414

1515
export interface OnCancel {
16-
readonly isResolved: boolean;
17-
readonly isRejected: boolean;
18-
readonly isCancelled: boolean;
16+
readonly isResolved: boolean;
17+
readonly isRejected: boolean;
18+
readonly isCancelled: boolean;
1919

20-
(cancelHandler: () => void): void;
20+
(cancelHandler: () => void): void;
2121
}
2222

2323
export class CancelablePromise<T> implements Promise<T> {
24-
readonly [Symbol.toStringTag]: string;
25-
26-
#isResolved: boolean;
27-
#isRejected: boolean;
28-
#isCancelled: boolean;
29-
readonly #cancelHandlers: (() => void)[];
30-
readonly #promise: Promise<T>;
31-
#resolve?: (value: T | PromiseLike<T>) => void;
32-
#reject?: (reason?: any) => void;
33-
34-
constructor(
35-
executor: (
36-
resolve: (value: T | PromiseLike<T>) => void,
37-
reject: (reason?: any) => void,
38-
onCancel: OnCancel
39-
) => void
40-
) {
41-
this.#isResolved = false;
42-
this.#isRejected = false;
43-
this.#isCancelled = false;
44-
this.#cancelHandlers = [];
45-
this.#promise = new Promise<T>((resolve, reject) => {
46-
this.#resolve = resolve;
47-
this.#reject = reject;
48-
49-
const onResolve = (value: T | PromiseLike<T>): void => {
50-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
51-
return;
52-
}
53-
this.#isResolved = true;
54-
this.#resolve?.(value);
55-
};
56-
57-
const onReject = (reason?: any): void => {
58-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
59-
return;
60-
}
61-
this.#isRejected = true;
62-
this.#reject?.(reason);
63-
};
64-
65-
const onCancel = (cancelHandler: () => void): void => {
66-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
67-
return;
68-
}
69-
this.#cancelHandlers.push(cancelHandler);
70-
};
71-
72-
Object.defineProperty(onCancel, 'isResolved', {
73-
get: (): boolean => this.#isResolved,
74-
});
75-
76-
Object.defineProperty(onCancel, 'isRejected', {
77-
get: (): boolean => this.#isRejected,
78-
});
79-
80-
Object.defineProperty(onCancel, 'isCancelled', {
81-
get: (): boolean => this.#isCancelled,
82-
});
83-
84-
return executor(onResolve, onReject, onCancel as OnCancel);
85-
});
86-
}
87-
88-
public then<TResult1 = T, TResult2 = never>(
89-
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
90-
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
91-
): Promise<TResult1 | TResult2> {
92-
return this.#promise.then(onFulfilled, onRejected);
93-
}
94-
95-
public catch<TResult = never>(
96-
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
97-
): Promise<T | TResult> {
98-
return this.#promise.catch(onRejected);
99-
}
100-
101-
public finally(onFinally?: (() => void) | null): Promise<T> {
102-
return this.#promise.finally(onFinally);
103-
}
104-
105-
public cancel(): void {
106-
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
107-
return;
108-
}
109-
this.#isCancelled = true;
110-
if (this.#cancelHandlers.length) {
111-
try {
112-
for (const cancelHandler of this.#cancelHandlers) {
113-
cancelHandler();
114-
}
115-
} catch (error) {
116-
console.warn('Cancellation threw an error', error);
117-
return;
118-
}
119-
}
120-
this.#cancelHandlers.length = 0;
121-
this.#reject?.(new CancelError('Request aborted'));
122-
}
123-
124-
public get isCancelled(): boolean {
125-
return this.#isCancelled;
126-
}
24+
readonly [Symbol.toStringTag]: string;
25+
26+
#isResolved: boolean;
27+
#isRejected: boolean;
28+
#isCancelled: boolean;
29+
readonly #cancelHandlers: (() => void)[];
30+
readonly #promise: Promise<T>;
31+
#resolve?: (value: T | PromiseLike<T>) => void;
32+
#reject?: (reason?: any) => void;
33+
34+
constructor(
35+
executor: (
36+
resolve: (value: T | PromiseLike<T>) => void,
37+
reject: (reason?: any) => void,
38+
onCancel: OnCancel
39+
) => void
40+
) {
41+
this.#isResolved = false;
42+
this.#isRejected = false;
43+
this.#isCancelled = false;
44+
this.#cancelHandlers = [];
45+
this.#promise = new Promise<T>((resolve, reject) => {
46+
this.#resolve = resolve;
47+
this.#reject = reject;
48+
49+
const onResolve = (value: T | PromiseLike<T>): void => {
50+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
51+
return;
52+
}
53+
this.#isResolved = true;
54+
this.#resolve?.(value);
55+
};
56+
57+
const onReject = (reason?: any): void => {
58+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
59+
return;
60+
}
61+
this.#isRejected = true;
62+
this.#reject?.(reason);
63+
};
64+
65+
const onCancel = (cancelHandler: () => void): void => {
66+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
67+
return;
68+
}
69+
this.#cancelHandlers.push(cancelHandler);
70+
};
71+
72+
Object.defineProperty(onCancel, 'isResolved', {
73+
get: (): boolean => this.#isResolved,
74+
});
75+
76+
Object.defineProperty(onCancel, 'isRejected', {
77+
get: (): boolean => this.#isRejected,
78+
});
79+
80+
Object.defineProperty(onCancel, 'isCancelled', {
81+
get: (): boolean => this.#isCancelled,
82+
});
83+
84+
return executor(onResolve, onReject, onCancel as OnCancel);
85+
});
86+
}
87+
88+
public then<TResult1 = T, TResult2 = never>(
89+
onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
90+
onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null
91+
): Promise<TResult1 | TResult2> {
92+
return this.#promise.then(onFulfilled, onRejected);
93+
}
94+
95+
public catch<TResult = never>(
96+
onRejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null
97+
): Promise<T | TResult> {
98+
return this.#promise.catch(onRejected);
99+
}
100+
101+
public finally(onFinally?: (() => void) | null): Promise<T> {
102+
return this.#promise.finally(onFinally);
103+
}
104+
105+
public cancel(): void {
106+
if (this.#isResolved || this.#isRejected || this.#isCancelled) {
107+
return;
108+
}
109+
this.#isCancelled = true;
110+
if (this.#cancelHandlers.length) {
111+
try {
112+
for (const cancelHandler of this.#cancelHandlers) {
113+
cancelHandler();
114+
}
115+
} catch (error) {
116+
console.warn('Cancellation threw an error', error);
117+
return;
118+
}
119+
}
120+
this.#cancelHandlers.length = 0;
121+
this.#reject?.(new CancelError('Request aborted'));
122+
}
123+
124+
public get isCancelled(): boolean {
125+
return this.#isCancelled;
126+
}
127127
}

src/templates/core/OpenAPI.hbs

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
66
type Headers = Record<string, string>;
77

88
type Config = {
9-
BASE: string;
10-
VERSION: string;
11-
WITH_CREDENTIALS: boolean;
12-
CREDENTIALS: 'include' | 'omit' | 'same-origin';
13-
TOKEN?: string | Resolver<string>;
14-
USERNAME?: string | Resolver<string>;
15-
PASSWORD?: string | Resolver<string>;
16-
HEADERS?: Headers | Resolver<Headers>;
17-
ENCODE_PATH?: (path: string) => string;
9+
BASE: string;
10+
VERSION: string;
11+
WITH_CREDENTIALS: boolean;
12+
CREDENTIALS: 'include' | 'omit' | 'same-origin';
13+
TOKEN?: string | Resolver<string>;
14+
USERNAME?: string | Resolver<string>;
15+
PASSWORD?: string | Resolver<string>;
16+
HEADERS?: Headers | Resolver<Headers>;
17+
ENCODE_PATH?: (path: string) => string;
1818
};
1919

2020
export const OpenAPI: Config = {
21-
BASE: '{{{server}}}',
22-
VERSION: '{{{version}}}',
23-
WITH_CREDENTIALS: false,
24-
CREDENTIALS: 'include',
25-
TOKEN: undefined,
26-
USERNAME: undefined,
27-
PASSWORD: undefined,
28-
HEADERS: undefined,
29-
ENCODE_PATH: undefined,
21+
BASE: '{{{server}}}',
22+
VERSION: '{{{version}}}',
23+
WITH_CREDENTIALS: false,
24+
CREDENTIALS: 'include',
25+
TOKEN: undefined,
26+
USERNAME: undefined,
27+
PASSWORD: undefined,
28+
HEADERS: undefined,
29+
ENCODE_PATH: undefined,
3030
};

0 commit comments

Comments
 (0)