Skip to content

Commit 5d52e3e

Browse files
committed
- Latest dependencies
1 parent cf45ccd commit 5d52e3e

File tree

8 files changed

+88
-37
lines changed

8 files changed

+88
-37
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"@typescript-eslint/parser": "4.2.0",
9191
"codecov": "3.7.2",
9292
"eslint": "7.9.0",
93-
"eslint-config-prettier": "6.11.0",
93+
"eslint-config-prettier": "6.12.0",
9494
"eslint-plugin-prettier": "3.1.4",
9595
"eslint-plugin-simple-import-sort": "5.0.3",
9696
"express": "4.17.1",
@@ -101,7 +101,7 @@
101101
"puppeteer": "5.3.1",
102102
"rollup": "2.28.2",
103103
"rollup-plugin-terser": "7.0.2",
104-
"rollup-plugin-typescript2": "0.27.2",
104+
"rollup-plugin-typescript2": "0.27.3",
105105
"typescript": "4.0.3"
106106
}
107107
}

src/templates/core/fetch/request.hbs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
1+
{{>header}}
2+
13
import { ApiError } from './ApiError';
24
import { ApiRequestOptions } from './ApiRequestOptions';
35
import { ApiResult } from './ApiResult';
46
import { OpenAPI } from './OpenAPI';
57

68
{{>functions/isDefined}}
79

10+
811
{{>functions/getQueryString}}
912

13+
1014
{{>functions/getUrl}}
1115

16+
1217
{{>functions/getFormData}}
1318

19+
1420
{{>functions/getHeaders}}
1521

22+
1623
{{>fetch/getRequestBody}}
1724

25+
1826
{{>fetch/sendRequest}}
1927

28+
2029
{{>fetch/getResponseHeader}}
2130

31+
2232
{{>fetch/getResponseBody}}
2333

34+
2435
{{>functions/catchErrors}}
2536

2637

2738
/**
28-
* Request using fetch
29-
* @param options Request options
39+
* Request using fetch client
40+
* @param options The request options from the the service
3041
* @result ApiResult
3142
* @throws ApiError
3243
*/

src/templates/core/functions/getUrl.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function getUrl(options: ApiRequestOptions): string {
33
const url = `${OpenAPI.BASE}${path}`;
44

55
if (options.query) {
6-
return url + getQueryString(options.query);
6+
return `${url}${getQueryString(options.query)}`;
77
}
88
return url;
99
}

src/templates/core/node/request.hbs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{>header}}
2+
13
import { ApiError } from './ApiError';
24
import { ApiRequestOptions } from './ApiRequestOptions';
35
import { ApiResult } from './ApiResult';
@@ -7,31 +9,40 @@ import * as FormData from 'form-data';
79

810
{{>functions/isDefined}}
911

12+
1013
{{>functions/getQueryString}}
1114

15+
1216
{{>functions/getUrl}}
1317

18+
1419
{{>functions/getFormData}}
1520

21+
1622
{{>functions/getHeaders}}
1723

24+
1825
{{>node/getRequestBody}}
1926

27+
2028
{{>node/sendRequest}}
2129

30+
2231
{{>node/getResponseHeader}}
2332

33+
2434
{{>node/getResponseBody}}
2535

36+
2637
{{>functions/catchErrors}}
2738

2839

2940
/**
30-
* Request using node-fetch
31-
* @param options Request options
32-
* @result ApiResult
33-
* @throws ApiError
34-
*/
41+
* Request using node-fetch client
42+
* @param options The request options from the the service
43+
* @result ApiResult
44+
* @throws ApiError
45+
*/
3546
export async function request(options: ApiRequestOptions): Promise<ApiResult> {
3647
const url = getUrl(options);
3748
const response = await sendRequest(options, url);

src/templates/core/request.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{{>header}}
2-
31
{{#equals httpClient 'fetch'}}
42
{{>fetch/request}}
53
{{/equals}}

src/templates/core/xhr/request.hbs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1+
{{>header}}
2+
13
import { ApiError } from './ApiError';
24
import { ApiRequestOptions } from './ApiRequestOptions';
35
import { ApiResult } from './ApiResult';
46
import { OpenAPI } from './OpenAPI';
57

68
{{>functions/isDefined}}
79

10+
811
{{>functions/isSuccess}}
912

13+
1014
{{>functions/getQueryString}}
1115

16+
1217
{{>functions/getUrl}}
1318

19+
1420
{{>functions/getFormData}}
1521

22+
1623
{{>functions/getHeaders}}
1724

25+
1826
{{>xhr/getRequestBody}}
1927

28+
2029
{{>xhr/sendRequest}}
2130

31+
2232
{{>xhr/getResponseHeader}}
2333

34+
2435
{{>xhr/getResponseBody}}
2536

37+
2638
{{>functions/catchErrors}}
2739

40+
2841
/**
29-
* Request using XHR
30-
* @param options Request options
42+
* Request using XHR client
43+
* @param options The request options from the the service
3144
* @result ApiResult
3245
* @throws ApiError
3346
*/

test/__snapshots__/index.spec.js.snap

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { OpenAPI } from './OpenAPI';
8686
function isDefined<T>(value: T | null | undefined): value is Exclude<T, null | undefined> {
8787
return value !== undefined && value !== null;
8888
}
89+
8990
function getQueryString(params: Record<string, any>): string {
9091
const qs: string[] = [];
9192
Object.keys(params).forEach(key => {
@@ -105,15 +106,17 @@ function getQueryString(params: Record<string, any>): string {
105106
}
106107
return '';
107108
}
109+
108110
function getUrl(options: ApiRequestOptions): string {
109111
const path = options.path.replace(/[:]/g, '_');
110112
const url = \`\${OpenAPI.BASE}\${path}\`;
111113

112114
if (options.query) {
113-
return url + getQueryString(options.query);
115+
return \`\${url}\${getQueryString(options.query)}\`;
114116
}
115117
return url;
116118
}
119+
117120
function getFormData(params: Record<string, any>): FormData {
118121
const formData = new FormData();
119122
Object.keys(params).forEach(key => {
@@ -124,6 +127,7 @@ function getFormData(params: Record<string, any>): FormData {
124127
});
125128
return formData;
126129
}
130+
127131
function getHeaders(options: ApiRequestOptions): Headers {
128132
const headers = new Headers({
129133
Accept: 'application/json',
@@ -147,6 +151,7 @@ function getHeaders(options: ApiRequestOptions): Headers {
147151
}
148152
return headers;
149153
}
154+
150155
function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
151156
if (options.formData) {
152157
return getFormData(options.formData);
@@ -162,6 +167,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
162167
}
163168
return undefined;
164169
}
170+
165171
async function sendRequest(options: ApiRequestOptions, url: string): Promise<Response> {
166172
const request: RequestInit = {
167173
method: options.method,
@@ -170,6 +176,7 @@ async function sendRequest(options: ApiRequestOptions, url: string): Promise<Res
170176
};
171177
return await fetch(url, request);
172178
}
179+
173180
function getResponseHeader(response: Response, responseHeader?: string): string | null {
174181
if (responseHeader) {
175182
const content = response.headers.get(responseHeader);
@@ -179,6 +186,7 @@ function getResponseHeader(response: Response, responseHeader?: string): string
179186
}
180187
return null;
181188
}
189+
182190
async function getResponseBody(response: Response): Promise<any> {
183191
try {
184192
const contentType = response.headers.get('Content-Type');
@@ -196,6 +204,7 @@ async function getResponseBody(response: Response): Promise<any> {
196204
}
197205
return null;
198206
}
207+
199208
function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
200209
const errors: Record<number, string> = {
201210
400: 'Bad Request',
@@ -219,8 +228,8 @@ function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
219228
}
220229

221230
/**
222-
* Request using fetch
223-
* @param options Request options
231+
* Request using fetch client
232+
* @param options The request options from the the service
224233
* @result ApiResult
225234
* @throws ApiError
226235
*/
@@ -2108,6 +2117,7 @@ import { OpenAPI } from './OpenAPI';
21082117
function isDefined<T>(value: T | null | undefined): value is Exclude<T, null | undefined> {
21092118
return value !== undefined && value !== null;
21102119
}
2120+
21112121
function getQueryString(params: Record<string, any>): string {
21122122
const qs: string[] = [];
21132123
Object.keys(params).forEach(key => {
@@ -2127,15 +2137,17 @@ function getQueryString(params: Record<string, any>): string {
21272137
}
21282138
return '';
21292139
}
2140+
21302141
function getUrl(options: ApiRequestOptions): string {
21312142
const path = options.path.replace(/[:]/g, '_');
21322143
const url = \`\${OpenAPI.BASE}\${path}\`;
21332144

21342145
if (options.query) {
2135-
return url + getQueryString(options.query);
2146+
return \`\${url}\${getQueryString(options.query)}\`;
21362147
}
21372148
return url;
21382149
}
2150+
21392151
function getFormData(params: Record<string, any>): FormData {
21402152
const formData = new FormData();
21412153
Object.keys(params).forEach(key => {
@@ -2146,6 +2158,7 @@ function getFormData(params: Record<string, any>): FormData {
21462158
});
21472159
return formData;
21482160
}
2161+
21492162
function getHeaders(options: ApiRequestOptions): Headers {
21502163
const headers = new Headers({
21512164
Accept: 'application/json',
@@ -2169,6 +2182,7 @@ function getHeaders(options: ApiRequestOptions): Headers {
21692182
}
21702183
return headers;
21712184
}
2185+
21722186
function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
21732187
if (options.formData) {
21742188
return getFormData(options.formData);
@@ -2184,6 +2198,7 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
21842198
}
21852199
return undefined;
21862200
}
2201+
21872202
async function sendRequest(options: ApiRequestOptions, url: string): Promise<Response> {
21882203
const request: RequestInit = {
21892204
method: options.method,
@@ -2192,6 +2207,7 @@ async function sendRequest(options: ApiRequestOptions, url: string): Promise<Res
21922207
};
21932208
return await fetch(url, request);
21942209
}
2210+
21952211
function getResponseHeader(response: Response, responseHeader?: string): string | null {
21962212
if (responseHeader) {
21972213
const content = response.headers.get(responseHeader);
@@ -2201,6 +2217,7 @@ function getResponseHeader(response: Response, responseHeader?: string): string
22012217
}
22022218
return null;
22032219
}
2220+
22042221
async function getResponseBody(response: Response): Promise<any> {
22052222
try {
22062223
const contentType = response.headers.get('Content-Type');
@@ -2218,6 +2235,7 @@ async function getResponseBody(response: Response): Promise<any> {
22182235
}
22192236
return null;
22202237
}
2238+
22212239
function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
22222240
const errors: Record<number, string> = {
22232241
400: 'Bad Request',
@@ -2241,8 +2259,8 @@ function catchErrors(options: ApiRequestOptions, result: ApiResult): void {
22412259
}
22422260

22432261
/**
2244-
* Request using fetch
2245-
* @param options Request options
2262+
* Request using fetch client
2263+
* @param options The request options from the the service
22462264
* @result ApiResult
22472265
* @throws ApiError
22482266
*/

0 commit comments

Comments
 (0)