@grandlinex/swagger-mate 1.3.4 → 1.3.6

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.
Files changed (33) hide show
  1. package/dist/cjs/Swagger/Client/SwaggerClient.d.ts +0 -3
  2. package/dist/cjs/Swagger/Client/SwaggerClient.js +5 -38
  3. package/dist/cjs/index.d.ts +1 -1
  4. package/dist/cjs/index.js +1 -1
  5. package/dist/mjs/Swagger/Client/SwaggerClient.d.ts +0 -3
  6. package/dist/mjs/Swagger/Client/SwaggerClient.js +5 -38
  7. package/dist/mjs/index.d.ts +1 -1
  8. package/dist/mjs/index.js +1 -1
  9. package/package.json +7 -7
  10. package/res/templates/class/ApiCon.ts +1 -1
  11. package/res/templates/class/CApiCon.ts +1 -1
  12. package/res/templates/class/IApiCon.ts +1 -1
  13. package/res/templates/class/index.ts +2 -3
  14. package/dist/cjs/Swagger/debug/BaseCon.d.ts +0 -202
  15. package/dist/cjs/Swagger/debug/BaseCon.js +0 -432
  16. package/dist/cjs/Swagger/debug/FetchCon.d.ts +0 -3
  17. package/dist/cjs/Swagger/debug/FetchCon.js +0 -79
  18. package/dist/cjs/Swagger/debug/NodeCon.d.ts +0 -3
  19. package/dist/cjs/Swagger/debug/NodeCon.js +0 -158
  20. package/dist/cjs/Swagger/debug/index.d.ts +0 -5
  21. package/dist/cjs/Swagger/debug/index.js +0 -27
  22. package/dist/mjs/Swagger/debug/BaseCon.d.ts +0 -202
  23. package/dist/mjs/Swagger/debug/BaseCon.js +0 -425
  24. package/dist/mjs/Swagger/debug/FetchCon.d.ts +0 -3
  25. package/dist/mjs/Swagger/debug/FetchCon.js +0 -77
  26. package/dist/mjs/Swagger/debug/NodeCon.d.ts +0 -3
  27. package/dist/mjs/Swagger/debug/NodeCon.js +0 -120
  28. package/dist/mjs/Swagger/debug/index.d.ts +0 -5
  29. package/dist/mjs/Swagger/debug/index.js +0 -5
  30. package/res/templates/class/AxiosCon.ts +0 -49
  31. package/res/templates/class/BaseCon.ts +0 -533
  32. package/res/templates/class/FetchCon.ts +0 -93
  33. package/res/templates/class/NodeCon.ts +0 -172
@@ -1,77 +0,0 @@
1
- async function fcTransform(r) {
2
- const res = await r;
3
- const head = {};
4
- res.headers.forEach((val, key) => {
5
- head[key] = val;
6
- });
7
- let data = null;
8
- if (head['content-type']?.includes('application/json')) {
9
- data = await res.json();
10
- }
11
- else if (head['content-type']?.includes('form-data')) {
12
- data = await res.formData();
13
- }
14
- else if (head['content-type']?.includes('octet-stream')) {
15
- data = await res.arrayBuffer();
16
- }
17
- else if (head['content-type']?.includes('text/plain')) {
18
- data = await res.text();
19
- }
20
- return {
21
- code: res.status,
22
- data,
23
- headers: head,
24
- };
25
- }
26
- function bodyTransform(r, headers) {
27
- if (!r) {
28
- return {
29
- headers,
30
- };
31
- }
32
- if (r instanceof FormData) {
33
- return {
34
- body: r,
35
- headers: {
36
- ...headers,
37
- },
38
- };
39
- }
40
- return {
41
- body: JSON.stringify(r),
42
- headers: {
43
- ...headers,
44
- 'content-type': 'application/json',
45
- },
46
- };
47
- }
48
- const FetchCon = {
49
- get: async (url, config) => {
50
- return fcTransform(fetch(url, {
51
- method: 'GET',
52
- headers: {
53
- accept: 'application/json, text/plain, */*',
54
- ...config?.headers,
55
- },
56
- }));
57
- },
58
- post: async (url, body, config) => {
59
- return fcTransform(fetch(url, {
60
- method: 'POST',
61
- ...bodyTransform(body, config?.headers),
62
- }));
63
- },
64
- patch: async (url, body, config) => {
65
- return fcTransform(fetch(url, {
66
- method: 'PATCH',
67
- ...bodyTransform(body, config?.headers),
68
- }));
69
- },
70
- delete: async (url, config) => {
71
- return fcTransform(fetch(url, {
72
- method: 'DELETE',
73
- headers: config?.headers,
74
- }));
75
- },
76
- };
77
- export default FetchCon;
@@ -1,3 +0,0 @@
1
- import { ConHandle } from './BaseCon.js';
2
- declare const NodeCon: ConHandle;
3
- export default NodeCon;
@@ -1,120 +0,0 @@
1
- import FormData from 'form-data';
2
- import * as http from 'http';
3
- import * as https from 'https';
4
- function selectClient(url) {
5
- if (url.startsWith('https')) {
6
- return https;
7
- }
8
- return http;
9
- }
10
- async function fcTransform(message, raw) {
11
- let data = null;
12
- if (message.headers['content-type']?.includes('application/json')) {
13
- data = JSON.parse(raw);
14
- }
15
- else if (message.headers['content-type']?.includes('form-data')) {
16
- data = null; // await res.formData()
17
- }
18
- else if (message.headers['content-type']?.includes('octet-stream')) {
19
- data = Buffer.from(raw);
20
- }
21
- else if (message.headers['content-type']?.startsWith('text/')) {
22
- data = Buffer.from(raw).toString('utf8');
23
- }
24
- return {
25
- code: message.statusCode || -1,
26
- data,
27
- headers: message.headers,
28
- };
29
- }
30
- function bodyTransform(r, headers) {
31
- if (!r) {
32
- return {
33
- headers: headers || {},
34
- body: undefined,
35
- };
36
- }
37
- if (r instanceof FormData) {
38
- return {
39
- body: r,
40
- headers: {
41
- ...headers,
42
- 'content-type': 'multipart/form-data',
43
- },
44
- };
45
- }
46
- return {
47
- body: JSON.stringify(r),
48
- headers: {
49
- ...headers,
50
- 'content-type': 'application/json',
51
- },
52
- };
53
- }
54
- async function makeRequest(url, option, body, config) {
55
- return new Promise((resolve) => {
56
- let headers = config?.headers || {};
57
- let transForm = null;
58
- if (body) {
59
- let safeHeaders;
60
- if (option.headers &&
61
- typeof option.headers === 'object' &&
62
- !Array.isArray(option.headers)) {
63
- safeHeaders = option.headers;
64
- }
65
- transForm = bodyTransform(body, safeHeaders);
66
- headers = {
67
- ...headers,
68
- ...transForm.headers,
69
- };
70
- }
71
- const req = selectClient(url)
72
- .request(url, {
73
- headers,
74
- ...option,
75
- }, (res) => {
76
- let data = '';
77
- // A chunk of data has been received.
78
- res.on('data', (chunk) => {
79
- data += chunk;
80
- });
81
- // The whole response has been received. Print out the result.
82
- res.on('end', () => {
83
- resolve(fcTransform(res, data));
84
- });
85
- })
86
- .on('error', (err) => {
87
- console.log(`Error: ${err.message}`);
88
- resolve({
89
- code: -1,
90
- data: null,
91
- headers: {},
92
- });
93
- });
94
- if (transForm && transForm.body) {
95
- req.write(transForm.body);
96
- }
97
- req.end();
98
- });
99
- }
100
- const NodeCon = {
101
- get: async (url, config) => {
102
- return makeRequest(url, {}, undefined, config);
103
- },
104
- post: async (url, body, config) => {
105
- return makeRequest(url, {
106
- method: 'POST',
107
- }, body, config);
108
- },
109
- patch: async (url, body, config) => {
110
- return makeRequest(url, {
111
- method: 'PATCH',
112
- }, body, config);
113
- },
114
- delete: async (url, config) => {
115
- return makeRequest(url, {
116
- method: 'DELETE',
117
- }, undefined, config);
118
- },
119
- };
120
- export default NodeCon;
@@ -1,5 +0,0 @@
1
- import BaseCon from './BaseCon.js';
2
- import NodeCon from './NodeCon.js';
3
- import FetchCon from './FetchCon.js';
4
- export * from './BaseCon.js';
5
- export { NodeCon, FetchCon, BaseCon };
@@ -1,5 +0,0 @@
1
- import BaseCon from './BaseCon.js';
2
- import NodeCon from './NodeCon.js';
3
- import FetchCon from './FetchCon.js';
4
- export * from './BaseCon.js';
5
- export { NodeCon, FetchCon, BaseCon };
@@ -1,49 +0,0 @@
1
- import axios, { AxiosResponse } from 'axios';
2
- import { ConHandle, ConHandleResponse } from './BaseCon.js';
3
-
4
- async function acTransform<T>(
5
- r: Promise<AxiosResponse<T>>
6
- ): Promise<ConHandleResponse<T>> {
7
- const res = await r;
8
- return {
9
- code: res.status,
10
- data: res.data,
11
- headers: res.headers as Record<string, any>,
12
- };
13
- }
14
- const AxiosCon: ConHandle = {
15
- get: async (url, config) => {
16
- return acTransform(
17
- axios.get(url, {
18
- headers: config?.headers,
19
- validateStatus: (status) => true,
20
- })
21
- );
22
- },
23
- post: async (url, body, config) => {
24
- return acTransform(
25
- axios.post(url, body, {
26
- headers: config?.headers,
27
- validateStatus: (status) => true,
28
- })
29
- );
30
- },
31
- patch: async (url, body, config) => {
32
- return acTransform(
33
- axios.patch(url, body, {
34
- headers: config?.headers,
35
- validateStatus: (status) => true,
36
- })
37
- );
38
- },
39
- delete: async (url, config) => {
40
- return acTransform(
41
- axios.delete(url, {
42
- headers: config?.headers,
43
- validateStatus: (status) => true,
44
- })
45
- );
46
- },
47
- };
48
-
49
- export default AxiosCon;