@grandlinex/swagger-mate 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Swagger/Client/SwaggerClient.d.ts +0 -3
- package/dist/cjs/Swagger/Client/SwaggerClient.js +5 -38
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -1
- package/dist/mjs/Swagger/Client/SwaggerClient.d.ts +0 -3
- package/dist/mjs/Swagger/Client/SwaggerClient.js +5 -38
- package/dist/mjs/index.d.ts +0 -1
- package/dist/mjs/index.js +0 -1
- package/package.json +7 -7
- package/res/templates/class/ApiCon.ts +1 -1
- package/res/templates/class/CApiCon.ts +1 -1
- package/res/templates/class/IApiCon.ts +1 -1
- package/res/templates/class/index.ts +2 -3
- package/dist/cjs/Swagger/debug/BaseCon.d.ts +0 -172
- package/dist/cjs/Swagger/debug/BaseCon.js +0 -380
- package/dist/cjs/Swagger/debug/FetchCon.d.ts +0 -3
- package/dist/cjs/Swagger/debug/FetchCon.js +0 -79
- package/dist/cjs/Swagger/debug/NodeCon.d.ts +0 -3
- package/dist/cjs/Swagger/debug/NodeCon.js +0 -158
- package/dist/cjs/Swagger/debug/index.d.ts +0 -5
- package/dist/cjs/Swagger/debug/index.js +0 -27
- package/dist/mjs/Swagger/debug/BaseCon.d.ts +0 -172
- package/dist/mjs/Swagger/debug/BaseCon.js +0 -373
- package/dist/mjs/Swagger/debug/FetchCon.d.ts +0 -3
- package/dist/mjs/Swagger/debug/FetchCon.js +0 -77
- package/dist/mjs/Swagger/debug/NodeCon.d.ts +0 -3
- package/dist/mjs/Swagger/debug/NodeCon.js +0 -120
- package/dist/mjs/Swagger/debug/index.d.ts +0 -5
- package/dist/mjs/Swagger/debug/index.js +0 -5
- package/res/templates/class/AxiosCon.ts +0 -49
- package/res/templates/class/BaseCon.ts +0 -476
- package/res/templates/class/FetchCon.ts +0 -93
- package/res/templates/class/NodeCon.ts +0 -172
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { ConHandle, ConHandleResponse } from './BaseCon.js';
|
|
2
|
-
|
|
3
|
-
async function fcTransform<T>(
|
|
4
|
-
r: Promise<Response>,
|
|
5
|
-
): Promise<ConHandleResponse<T>> {
|
|
6
|
-
const res = await r;
|
|
7
|
-
const head: Record<string, any> = {};
|
|
8
|
-
|
|
9
|
-
res.headers.forEach((val: any, key: any) => {
|
|
10
|
-
head[key] = val;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
let data = null;
|
|
14
|
-
|
|
15
|
-
if (head['content-type']?.includes('application/json')) {
|
|
16
|
-
data = await res.json();
|
|
17
|
-
} else if (head['content-type']?.includes('form-data')) {
|
|
18
|
-
data = await res.formData();
|
|
19
|
-
} else if (head['content-type']?.includes('octet-stream')) {
|
|
20
|
-
data = await res.arrayBuffer();
|
|
21
|
-
} else if (head['content-type']?.includes('text/plain')) {
|
|
22
|
-
data = await res.text();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
code: res.status,
|
|
27
|
-
data,
|
|
28
|
-
headers: head,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function bodyTransform(r: any, headers?: Record<string, string>) {
|
|
33
|
-
if (!r) {
|
|
34
|
-
return {
|
|
35
|
-
headers,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
if (r instanceof FormData) {
|
|
39
|
-
return {
|
|
40
|
-
body: r,
|
|
41
|
-
headers: {
|
|
42
|
-
...headers,
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
body: JSON.stringify(r),
|
|
48
|
-
headers: {
|
|
49
|
-
...headers,
|
|
50
|
-
'content-type': 'application/json',
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const FetchCon: ConHandle = {
|
|
56
|
-
get: async (url, config) => {
|
|
57
|
-
return fcTransform(
|
|
58
|
-
fetch(url, {
|
|
59
|
-
method: 'GET',
|
|
60
|
-
headers: {
|
|
61
|
-
accept: 'application/json, text/plain, */*',
|
|
62
|
-
...config?.headers,
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
66
|
-
},
|
|
67
|
-
post: async (url, body, config) => {
|
|
68
|
-
return fcTransform(
|
|
69
|
-
fetch(url, {
|
|
70
|
-
method: 'POST',
|
|
71
|
-
...bodyTransform(body, config?.headers),
|
|
72
|
-
}),
|
|
73
|
-
);
|
|
74
|
-
},
|
|
75
|
-
patch: async (url, body, config) => {
|
|
76
|
-
return fcTransform(
|
|
77
|
-
fetch(url, {
|
|
78
|
-
method: 'PATCH',
|
|
79
|
-
...bodyTransform(body, config?.headers),
|
|
80
|
-
}),
|
|
81
|
-
);
|
|
82
|
-
},
|
|
83
|
-
delete: async (url, config) => {
|
|
84
|
-
return fcTransform(
|
|
85
|
-
fetch(url, {
|
|
86
|
-
method: 'DELETE',
|
|
87
|
-
headers: config?.headers,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export default FetchCon;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import FormData from 'form-data';
|
|
2
|
-
import * as http from 'http';
|
|
3
|
-
import * as https from 'https';
|
|
4
|
-
import { IncomingMessage } from 'http';
|
|
5
|
-
import { RequestOptions } from 'https';
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
ConHandle,
|
|
9
|
-
ConHandleConfig,
|
|
10
|
-
ConHandleResponse,
|
|
11
|
-
HeaderType,
|
|
12
|
-
} from './BaseCon.js';
|
|
13
|
-
|
|
14
|
-
function selectClient(url: string) {
|
|
15
|
-
if (url.startsWith('https')) {
|
|
16
|
-
return https;
|
|
17
|
-
}
|
|
18
|
-
return http;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function fcTransform<T>(
|
|
22
|
-
message: IncomingMessage,
|
|
23
|
-
raw: any,
|
|
24
|
-
): Promise<ConHandleResponse<T>> {
|
|
25
|
-
let data = null;
|
|
26
|
-
|
|
27
|
-
if (message.headers['content-type']?.includes('application/json')) {
|
|
28
|
-
data = JSON.parse(raw);
|
|
29
|
-
} else if (message.headers['content-type']?.includes('form-data')) {
|
|
30
|
-
data = null; // await res.formData()
|
|
31
|
-
} else if (message.headers['content-type']?.includes('octet-stream')) {
|
|
32
|
-
data = Buffer.from(raw);
|
|
33
|
-
} else if (message.headers['content-type']?.startsWith('text/')) {
|
|
34
|
-
data = Buffer.from(raw).toString('utf8');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
code: message.statusCode || -1,
|
|
39
|
-
data,
|
|
40
|
-
headers: message.headers,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function bodyTransform(
|
|
44
|
-
r: any,
|
|
45
|
-
headers?: Record<string, HeaderType>,
|
|
46
|
-
): {
|
|
47
|
-
headers: Record<string, HeaderType>;
|
|
48
|
-
body: any;
|
|
49
|
-
} {
|
|
50
|
-
if (!r) {
|
|
51
|
-
return {
|
|
52
|
-
headers: headers || {},
|
|
53
|
-
body: undefined,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (r instanceof FormData) {
|
|
57
|
-
return {
|
|
58
|
-
body: r,
|
|
59
|
-
headers: {
|
|
60
|
-
...headers,
|
|
61
|
-
'content-type': 'multipart/form-data',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
body: JSON.stringify(r),
|
|
67
|
-
headers: {
|
|
68
|
-
...headers,
|
|
69
|
-
'content-type': 'application/json',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
async function makeRequest<T, J>(
|
|
74
|
-
url: string,
|
|
75
|
-
option: RequestOptions,
|
|
76
|
-
body?: J,
|
|
77
|
-
config?: ConHandleConfig,
|
|
78
|
-
): Promise<ConHandleResponse<T>> {
|
|
79
|
-
return new Promise((resolve) => {
|
|
80
|
-
let headers: Record<string, any> = config?.headers || {};
|
|
81
|
-
let transForm = null;
|
|
82
|
-
if (body) {
|
|
83
|
-
let safeHeaders: Record<string, HeaderType> | undefined;
|
|
84
|
-
if (
|
|
85
|
-
option.headers &&
|
|
86
|
-
typeof option.headers === 'object' &&
|
|
87
|
-
!Array.isArray(option.headers)
|
|
88
|
-
) {
|
|
89
|
-
safeHeaders = option.headers as Record<string, HeaderType>;
|
|
90
|
-
}
|
|
91
|
-
transForm = bodyTransform(body, safeHeaders);
|
|
92
|
-
headers = {
|
|
93
|
-
...headers,
|
|
94
|
-
...transForm.headers,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const req = selectClient(url)
|
|
99
|
-
.request(
|
|
100
|
-
url,
|
|
101
|
-
{
|
|
102
|
-
headers,
|
|
103
|
-
...option,
|
|
104
|
-
},
|
|
105
|
-
(res) => {
|
|
106
|
-
let data = '';
|
|
107
|
-
|
|
108
|
-
// A chunk of data has been received.
|
|
109
|
-
res.on('data', (chunk) => {
|
|
110
|
-
data += chunk;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// The whole response has been received. Print out the result.
|
|
114
|
-
res.on('end', () => {
|
|
115
|
-
resolve(fcTransform(res, data));
|
|
116
|
-
});
|
|
117
|
-
},
|
|
118
|
-
)
|
|
119
|
-
.on('error', (err) => {
|
|
120
|
-
console.log(`Error: ${err.message}`);
|
|
121
|
-
|
|
122
|
-
resolve({
|
|
123
|
-
code: -1,
|
|
124
|
-
data: null,
|
|
125
|
-
headers: {},
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
if (transForm && transForm.body) {
|
|
130
|
-
req.write(transForm.body);
|
|
131
|
-
}
|
|
132
|
-
req.end();
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const NodeCon: ConHandle = {
|
|
137
|
-
get: async (url, config) => {
|
|
138
|
-
return makeRequest(url, {}, undefined, config);
|
|
139
|
-
},
|
|
140
|
-
post: async (url, body, config) => {
|
|
141
|
-
return makeRequest(
|
|
142
|
-
url,
|
|
143
|
-
{
|
|
144
|
-
method: 'POST',
|
|
145
|
-
},
|
|
146
|
-
body,
|
|
147
|
-
config,
|
|
148
|
-
);
|
|
149
|
-
},
|
|
150
|
-
patch: async (url, body, config) => {
|
|
151
|
-
return makeRequest(
|
|
152
|
-
url,
|
|
153
|
-
{
|
|
154
|
-
method: 'PATCH',
|
|
155
|
-
},
|
|
156
|
-
body,
|
|
157
|
-
config,
|
|
158
|
-
);
|
|
159
|
-
},
|
|
160
|
-
delete: async (url, config) => {
|
|
161
|
-
return makeRequest(
|
|
162
|
-
url,
|
|
163
|
-
{
|
|
164
|
-
method: 'DELETE',
|
|
165
|
-
},
|
|
166
|
-
undefined,
|
|
167
|
-
config,
|
|
168
|
-
);
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
export default NodeCon;
|