routesync 1.0.17 → 1.0.18
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/cli.js +43 -3
- package/dist/core.d.mts +6 -1
- package/dist/core.d.ts +6 -1
- package/dist/core.js +70 -6
- package/dist/core.mjs +65 -5
- package/dist/sdk.js +60 -4
- package/dist/sdk.mjs +60 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8733,6 +8733,45 @@ ${fields.join(",\n")}
|
|
|
8733
8733
|
}
|
|
8734
8734
|
};
|
|
8735
8735
|
|
|
8736
|
+
// packages/core/src/utils.ts
|
|
8737
|
+
function camelCase(str) {
|
|
8738
|
+
return str.replace(/_([a-z0-9])/g, (_, p1) => p1.toUpperCase());
|
|
8739
|
+
}
|
|
8740
|
+
|
|
8741
|
+
// packages/core/src/client/HttpClient.ts
|
|
8742
|
+
var import_axios = __toESM(require("axios"));
|
|
8743
|
+
|
|
8744
|
+
// packages/core/src/auth/TokenManager.ts
|
|
8745
|
+
var _TokenManager = class _TokenManager {
|
|
8746
|
+
constructor() {
|
|
8747
|
+
this.token = null;
|
|
8748
|
+
}
|
|
8749
|
+
set(token) {
|
|
8750
|
+
this.token = token;
|
|
8751
|
+
if (typeof localStorage !== "undefined") {
|
|
8752
|
+
localStorage.setItem(_TokenManager.TOKEN_KEY, token);
|
|
8753
|
+
}
|
|
8754
|
+
}
|
|
8755
|
+
get() {
|
|
8756
|
+
if (this.token) return this.token;
|
|
8757
|
+
if (typeof localStorage !== "undefined") {
|
|
8758
|
+
return localStorage.getItem(_TokenManager.TOKEN_KEY);
|
|
8759
|
+
}
|
|
8760
|
+
return null;
|
|
8761
|
+
}
|
|
8762
|
+
clear() {
|
|
8763
|
+
this.token = null;
|
|
8764
|
+
if (typeof localStorage !== "undefined") {
|
|
8765
|
+
localStorage.removeItem(_TokenManager.TOKEN_KEY);
|
|
8766
|
+
}
|
|
8767
|
+
}
|
|
8768
|
+
exists() {
|
|
8769
|
+
return this.get() !== null;
|
|
8770
|
+
}
|
|
8771
|
+
};
|
|
8772
|
+
_TokenManager.TOKEN_KEY = "routesync_token";
|
|
8773
|
+
var TokenManager = _TokenManager;
|
|
8774
|
+
|
|
8736
8775
|
// packages/cli/src/generators/TypeGenerator.ts
|
|
8737
8776
|
var import_path3 = __toESM(require("path"));
|
|
8738
8777
|
var import_fs_extra4 = __toESM(require_lib());
|
|
@@ -8836,7 +8875,8 @@ var TypeGenerator = class {
|
|
|
8836
8875
|
if (ruleStr.includes("nullable")) {
|
|
8837
8876
|
zodRule += ".nullable()";
|
|
8838
8877
|
}
|
|
8839
|
-
const
|
|
8878
|
+
const camelField = camelCase(field);
|
|
8879
|
+
const safeField = camelField.match(/^[a-zA-Z_$][a-zA-Z0-9_$]*$/) ? camelField : `"${camelField}"`;
|
|
8840
8880
|
lines.push(` ${safeField}: ${zodRule},`);
|
|
8841
8881
|
}
|
|
8842
8882
|
lines.push(`})`);
|
|
@@ -9092,11 +9132,11 @@ var ModelGenerator = class {
|
|
|
9092
9132
|
tsType = this.mapCastToTs(castType, tsType);
|
|
9093
9133
|
}
|
|
9094
9134
|
const nullable = col.nullable ? " | null" : "";
|
|
9095
|
-
lines.push(` ${col.name}${isOptional}: ${tsType}${nullable}`);
|
|
9135
|
+
lines.push(` ${camelCase(col.name)}${isOptional}: ${tsType}${nullable}`);
|
|
9096
9136
|
}
|
|
9097
9137
|
const appends = Array.isArray(model.appends) ? model.appends : [];
|
|
9098
9138
|
for (const append of appends) {
|
|
9099
|
-
lines.push(` ${append}: unknown // appended attribute`);
|
|
9139
|
+
lines.push(` ${camelCase(append)}: unknown // appended attribute`);
|
|
9100
9140
|
}
|
|
9101
9141
|
lines.push(`}`);
|
|
9102
9142
|
lines.push(``);
|
package/dist/core.d.mts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosInstance, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
|
|
3
|
+
declare function camelCase(str: string): string;
|
|
4
|
+
declare function snakeCase(str: string): string;
|
|
5
|
+
declare function camelCaseKeys(obj: any): any;
|
|
6
|
+
declare function snakeCaseKeys(obj: any): any;
|
|
7
|
+
|
|
3
8
|
interface ServiceConfig {
|
|
4
9
|
baseURL: string;
|
|
5
10
|
token?: string;
|
|
@@ -228,4 +233,4 @@ interface ParsedModel {
|
|
|
228
233
|
casts?: Record<string, string>;
|
|
229
234
|
}
|
|
230
235
|
|
|
231
|
-
export { type ApiDefinition, ApiError, type ApiResponse, type AuthConfig, AuthMiddleware, ErrorHandler, HttpClient, type HttpMethod, Interceptor, type PaginationMeta, type ParsedChannel, type ParsedColumn, type ParsedModel, type ParsedRoute, PathResolver, QueryBuilder, Request, type RequestOptions, Response, type RetryConfig, type RouteDefinition, type RouteManifest, type RouteMapper, type RouteParserSchema, type RouteSchema, type RouteSchemaMap, type RouteSchemaValue, type RouteTransform, type RouteTransformMap, type ServiceConfig, TokenManager };
|
|
236
|
+
export { type ApiDefinition, ApiError, type ApiResponse, type AuthConfig, AuthMiddleware, ErrorHandler, HttpClient, type HttpMethod, Interceptor, type PaginationMeta, type ParsedChannel, type ParsedColumn, type ParsedModel, type ParsedRoute, PathResolver, QueryBuilder, Request, type RequestOptions, Response, type RetryConfig, type RouteDefinition, type RouteManifest, type RouteMapper, type RouteParserSchema, type RouteSchema, type RouteSchemaMap, type RouteSchemaValue, type RouteTransform, type RouteTransformMap, type ServiceConfig, TokenManager, camelCase, camelCaseKeys, snakeCase, snakeCaseKeys };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosInstance, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
|
|
3
|
+
declare function camelCase(str: string): string;
|
|
4
|
+
declare function snakeCase(str: string): string;
|
|
5
|
+
declare function camelCaseKeys(obj: any): any;
|
|
6
|
+
declare function snakeCaseKeys(obj: any): any;
|
|
7
|
+
|
|
3
8
|
interface ServiceConfig {
|
|
4
9
|
baseURL: string;
|
|
5
10
|
token?: string;
|
|
@@ -228,4 +233,4 @@ interface ParsedModel {
|
|
|
228
233
|
casts?: Record<string, string>;
|
|
229
234
|
}
|
|
230
235
|
|
|
231
|
-
export { type ApiDefinition, ApiError, type ApiResponse, type AuthConfig, AuthMiddleware, ErrorHandler, HttpClient, type HttpMethod, Interceptor, type PaginationMeta, type ParsedChannel, type ParsedColumn, type ParsedModel, type ParsedRoute, PathResolver, QueryBuilder, Request, type RequestOptions, Response, type RetryConfig, type RouteDefinition, type RouteManifest, type RouteMapper, type RouteParserSchema, type RouteSchema, type RouteSchemaMap, type RouteSchemaValue, type RouteTransform, type RouteTransformMap, type ServiceConfig, TokenManager };
|
|
236
|
+
export { type ApiDefinition, ApiError, type ApiResponse, type AuthConfig, AuthMiddleware, ErrorHandler, HttpClient, type HttpMethod, Interceptor, type PaginationMeta, type ParsedChannel, type ParsedColumn, type ParsedModel, type ParsedRoute, PathResolver, QueryBuilder, Request, type RequestOptions, Response, type RetryConfig, type RouteDefinition, type RouteManifest, type RouteMapper, type RouteParserSchema, type RouteSchema, type RouteSchemaMap, type RouteSchemaValue, type RouteTransform, type RouteTransformMap, type ServiceConfig, TokenManager, camelCase, camelCaseKeys, snakeCase, snakeCaseKeys };
|
package/dist/core.js
CHANGED
|
@@ -39,10 +39,50 @@ __export(src_exports, {
|
|
|
39
39
|
QueryBuilder: () => QueryBuilder,
|
|
40
40
|
Request: () => Request,
|
|
41
41
|
Response: () => Response,
|
|
42
|
-
TokenManager: () => TokenManager
|
|
42
|
+
TokenManager: () => TokenManager,
|
|
43
|
+
camelCase: () => camelCase,
|
|
44
|
+
camelCaseKeys: () => camelCaseKeys,
|
|
45
|
+
snakeCase: () => snakeCase,
|
|
46
|
+
snakeCaseKeys: () => snakeCaseKeys
|
|
43
47
|
});
|
|
44
48
|
module.exports = __toCommonJS(src_exports);
|
|
45
49
|
|
|
50
|
+
// packages/core/src/utils.ts
|
|
51
|
+
function camelCase(str) {
|
|
52
|
+
return str.replace(/_([a-z0-9])/g, (_, p1) => p1.toUpperCase());
|
|
53
|
+
}
|
|
54
|
+
function snakeCase(str) {
|
|
55
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
56
|
+
}
|
|
57
|
+
function camelCaseKeys(obj) {
|
|
58
|
+
if (Array.isArray(obj)) {
|
|
59
|
+
return obj.map((v) => camelCaseKeys(v));
|
|
60
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
61
|
+
return Object.keys(obj).reduce(
|
|
62
|
+
(result, key) => {
|
|
63
|
+
result[camelCase(key)] = camelCaseKeys(obj[key]);
|
|
64
|
+
return result;
|
|
65
|
+
},
|
|
66
|
+
{}
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
function snakeCaseKeys(obj) {
|
|
72
|
+
if (Array.isArray(obj)) {
|
|
73
|
+
return obj.map((v) => snakeCaseKeys(v));
|
|
74
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
75
|
+
return Object.keys(obj).reduce(
|
|
76
|
+
(result, key) => {
|
|
77
|
+
result[snakeCase(key)] = snakeCaseKeys(obj[key]);
|
|
78
|
+
return result;
|
|
79
|
+
},
|
|
80
|
+
{}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
85
|
+
|
|
46
86
|
// packages/core/src/client/HttpClient.ts
|
|
47
87
|
var import_axios = __toESM(require("axios"));
|
|
48
88
|
var HttpClient = class {
|
|
@@ -62,8 +102,24 @@ var HttpClient = class {
|
|
|
62
102
|
this.setupInterceptors();
|
|
63
103
|
}
|
|
64
104
|
setupInterceptors() {
|
|
105
|
+
this.client.interceptors.request.use(
|
|
106
|
+
(config) => {
|
|
107
|
+
if (config.data && !(config.data instanceof FormData)) {
|
|
108
|
+
config.data = snakeCaseKeys(config.data);
|
|
109
|
+
}
|
|
110
|
+
if (config.params) {
|
|
111
|
+
config.params = snakeCaseKeys(config.params);
|
|
112
|
+
}
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
);
|
|
65
116
|
this.client.interceptors.response.use(
|
|
66
|
-
(response) =>
|
|
117
|
+
(response) => {
|
|
118
|
+
if (response.data) {
|
|
119
|
+
response.data = camelCaseKeys(response.data);
|
|
120
|
+
}
|
|
121
|
+
return response;
|
|
122
|
+
},
|
|
67
123
|
(error) => {
|
|
68
124
|
const message = error.response?.data?.message ?? error.message ?? "Unknown error";
|
|
69
125
|
return Promise.reject({
|
|
@@ -114,10 +170,14 @@ var HttpClient = class {
|
|
|
114
170
|
return formData;
|
|
115
171
|
}
|
|
116
172
|
prepareRequest(body, config) {
|
|
117
|
-
|
|
118
|
-
|
|
173
|
+
let finalBody = body;
|
|
174
|
+
if (finalBody && typeof finalBody === "object" && !(finalBody instanceof FormData)) {
|
|
175
|
+
finalBody = snakeCaseKeys(finalBody);
|
|
176
|
+
}
|
|
177
|
+
if (!finalBody || !this.hasFiles(finalBody)) {
|
|
178
|
+
return { processedBody: finalBody, processedConfig: config };
|
|
119
179
|
}
|
|
120
|
-
const formData = this.toFormData(
|
|
180
|
+
const formData = this.toFormData(finalBody);
|
|
121
181
|
const newConfig = { ...config };
|
|
122
182
|
if (!newConfig.headers) {
|
|
123
183
|
newConfig.headers = {};
|
|
@@ -397,5 +457,9 @@ var ErrorHandler = class {
|
|
|
397
457
|
QueryBuilder,
|
|
398
458
|
Request,
|
|
399
459
|
Response,
|
|
400
|
-
TokenManager
|
|
460
|
+
TokenManager,
|
|
461
|
+
camelCase,
|
|
462
|
+
camelCaseKeys,
|
|
463
|
+
snakeCase,
|
|
464
|
+
snakeCaseKeys
|
|
401
465
|
});
|
package/dist/core.mjs
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
+
// packages/core/src/utils.ts
|
|
2
|
+
function camelCase(str) {
|
|
3
|
+
return str.replace(/_([a-z0-9])/g, (_, p1) => p1.toUpperCase());
|
|
4
|
+
}
|
|
5
|
+
function snakeCase(str) {
|
|
6
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
7
|
+
}
|
|
8
|
+
function camelCaseKeys(obj) {
|
|
9
|
+
if (Array.isArray(obj)) {
|
|
10
|
+
return obj.map((v) => camelCaseKeys(v));
|
|
11
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
12
|
+
return Object.keys(obj).reduce(
|
|
13
|
+
(result, key) => {
|
|
14
|
+
result[camelCase(key)] = camelCaseKeys(obj[key]);
|
|
15
|
+
return result;
|
|
16
|
+
},
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function snakeCaseKeys(obj) {
|
|
23
|
+
if (Array.isArray(obj)) {
|
|
24
|
+
return obj.map((v) => snakeCaseKeys(v));
|
|
25
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
26
|
+
return Object.keys(obj).reduce(
|
|
27
|
+
(result, key) => {
|
|
28
|
+
result[snakeCase(key)] = snakeCaseKeys(obj[key]);
|
|
29
|
+
return result;
|
|
30
|
+
},
|
|
31
|
+
{}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
|
|
1
37
|
// packages/core/src/client/HttpClient.ts
|
|
2
38
|
import axios from "axios";
|
|
3
39
|
var HttpClient = class {
|
|
@@ -17,8 +53,24 @@ var HttpClient = class {
|
|
|
17
53
|
this.setupInterceptors();
|
|
18
54
|
}
|
|
19
55
|
setupInterceptors() {
|
|
56
|
+
this.client.interceptors.request.use(
|
|
57
|
+
(config) => {
|
|
58
|
+
if (config.data && !(config.data instanceof FormData)) {
|
|
59
|
+
config.data = snakeCaseKeys(config.data);
|
|
60
|
+
}
|
|
61
|
+
if (config.params) {
|
|
62
|
+
config.params = snakeCaseKeys(config.params);
|
|
63
|
+
}
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
);
|
|
20
67
|
this.client.interceptors.response.use(
|
|
21
|
-
(response) =>
|
|
68
|
+
(response) => {
|
|
69
|
+
if (response.data) {
|
|
70
|
+
response.data = camelCaseKeys(response.data);
|
|
71
|
+
}
|
|
72
|
+
return response;
|
|
73
|
+
},
|
|
22
74
|
(error) => {
|
|
23
75
|
const message = error.response?.data?.message ?? error.message ?? "Unknown error";
|
|
24
76
|
return Promise.reject({
|
|
@@ -69,10 +121,14 @@ var HttpClient = class {
|
|
|
69
121
|
return formData;
|
|
70
122
|
}
|
|
71
123
|
prepareRequest(body, config) {
|
|
72
|
-
|
|
73
|
-
|
|
124
|
+
let finalBody = body;
|
|
125
|
+
if (finalBody && typeof finalBody === "object" && !(finalBody instanceof FormData)) {
|
|
126
|
+
finalBody = snakeCaseKeys(finalBody);
|
|
127
|
+
}
|
|
128
|
+
if (!finalBody || !this.hasFiles(finalBody)) {
|
|
129
|
+
return { processedBody: finalBody, processedConfig: config };
|
|
74
130
|
}
|
|
75
|
-
const formData = this.toFormData(
|
|
131
|
+
const formData = this.toFormData(finalBody);
|
|
76
132
|
const newConfig = { ...config };
|
|
77
133
|
if (!newConfig.headers) {
|
|
78
134
|
newConfig.headers = {};
|
|
@@ -351,5 +407,9 @@ export {
|
|
|
351
407
|
QueryBuilder,
|
|
352
408
|
Request,
|
|
353
409
|
Response,
|
|
354
|
-
TokenManager
|
|
410
|
+
TokenManager,
|
|
411
|
+
camelCase,
|
|
412
|
+
camelCaseKeys,
|
|
413
|
+
snakeCase,
|
|
414
|
+
snakeCaseKeys
|
|
355
415
|
};
|
package/dist/sdk.js
CHANGED
|
@@ -47,6 +47,42 @@ __export(src_exports, {
|
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(src_exports);
|
|
49
49
|
|
|
50
|
+
// packages/core/src/utils.ts
|
|
51
|
+
function camelCase(str) {
|
|
52
|
+
return str.replace(/_([a-z0-9])/g, (_, p1) => p1.toUpperCase());
|
|
53
|
+
}
|
|
54
|
+
function snakeCase(str) {
|
|
55
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
56
|
+
}
|
|
57
|
+
function camelCaseKeys(obj) {
|
|
58
|
+
if (Array.isArray(obj)) {
|
|
59
|
+
return obj.map((v) => camelCaseKeys(v));
|
|
60
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
61
|
+
return Object.keys(obj).reduce(
|
|
62
|
+
(result, key) => {
|
|
63
|
+
result[camelCase(key)] = camelCaseKeys(obj[key]);
|
|
64
|
+
return result;
|
|
65
|
+
},
|
|
66
|
+
{}
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return obj;
|
|
70
|
+
}
|
|
71
|
+
function snakeCaseKeys(obj) {
|
|
72
|
+
if (Array.isArray(obj)) {
|
|
73
|
+
return obj.map((v) => snakeCaseKeys(v));
|
|
74
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
75
|
+
return Object.keys(obj).reduce(
|
|
76
|
+
(result, key) => {
|
|
77
|
+
result[snakeCase(key)] = snakeCaseKeys(obj[key]);
|
|
78
|
+
return result;
|
|
79
|
+
},
|
|
80
|
+
{}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return obj;
|
|
84
|
+
}
|
|
85
|
+
|
|
50
86
|
// packages/core/src/client/HttpClient.ts
|
|
51
87
|
var import_axios = __toESM(require("axios"));
|
|
52
88
|
var HttpClient = class {
|
|
@@ -66,8 +102,24 @@ var HttpClient = class {
|
|
|
66
102
|
this.setupInterceptors();
|
|
67
103
|
}
|
|
68
104
|
setupInterceptors() {
|
|
105
|
+
this.client.interceptors.request.use(
|
|
106
|
+
(config) => {
|
|
107
|
+
if (config.data && !(config.data instanceof FormData)) {
|
|
108
|
+
config.data = snakeCaseKeys(config.data);
|
|
109
|
+
}
|
|
110
|
+
if (config.params) {
|
|
111
|
+
config.params = snakeCaseKeys(config.params);
|
|
112
|
+
}
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
);
|
|
69
116
|
this.client.interceptors.response.use(
|
|
70
|
-
(response) =>
|
|
117
|
+
(response) => {
|
|
118
|
+
if (response.data) {
|
|
119
|
+
response.data = camelCaseKeys(response.data);
|
|
120
|
+
}
|
|
121
|
+
return response;
|
|
122
|
+
},
|
|
71
123
|
(error) => {
|
|
72
124
|
const message = error.response?.data?.message ?? error.message ?? "Unknown error";
|
|
73
125
|
return Promise.reject({
|
|
@@ -118,10 +170,14 @@ var HttpClient = class {
|
|
|
118
170
|
return formData;
|
|
119
171
|
}
|
|
120
172
|
prepareRequest(body, config) {
|
|
121
|
-
|
|
122
|
-
|
|
173
|
+
let finalBody = body;
|
|
174
|
+
if (finalBody && typeof finalBody === "object" && !(finalBody instanceof FormData)) {
|
|
175
|
+
finalBody = snakeCaseKeys(finalBody);
|
|
176
|
+
}
|
|
177
|
+
if (!finalBody || !this.hasFiles(finalBody)) {
|
|
178
|
+
return { processedBody: finalBody, processedConfig: config };
|
|
123
179
|
}
|
|
124
|
-
const formData = this.toFormData(
|
|
180
|
+
const formData = this.toFormData(finalBody);
|
|
125
181
|
const newConfig = { ...config };
|
|
126
182
|
if (!newConfig.headers) {
|
|
127
183
|
newConfig.headers = {};
|
package/dist/sdk.mjs
CHANGED
|
@@ -5,6 +5,42 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
+
// packages/core/src/utils.ts
|
|
9
|
+
function camelCase(str) {
|
|
10
|
+
return str.replace(/_([a-z0-9])/g, (_, p1) => p1.toUpperCase());
|
|
11
|
+
}
|
|
12
|
+
function snakeCase(str) {
|
|
13
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
14
|
+
}
|
|
15
|
+
function camelCaseKeys(obj) {
|
|
16
|
+
if (Array.isArray(obj)) {
|
|
17
|
+
return obj.map((v) => camelCaseKeys(v));
|
|
18
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
19
|
+
return Object.keys(obj).reduce(
|
|
20
|
+
(result, key) => {
|
|
21
|
+
result[camelCase(key)] = camelCaseKeys(obj[key]);
|
|
22
|
+
return result;
|
|
23
|
+
},
|
|
24
|
+
{}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
function snakeCaseKeys(obj) {
|
|
30
|
+
if (Array.isArray(obj)) {
|
|
31
|
+
return obj.map((v) => snakeCaseKeys(v));
|
|
32
|
+
} else if (obj !== null && obj.constructor === Object) {
|
|
33
|
+
return Object.keys(obj).reduce(
|
|
34
|
+
(result, key) => {
|
|
35
|
+
result[snakeCase(key)] = snakeCaseKeys(obj[key]);
|
|
36
|
+
return result;
|
|
37
|
+
},
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
|
|
8
44
|
// packages/core/src/client/HttpClient.ts
|
|
9
45
|
import axios from "axios";
|
|
10
46
|
var HttpClient = class {
|
|
@@ -24,8 +60,24 @@ var HttpClient = class {
|
|
|
24
60
|
this.setupInterceptors();
|
|
25
61
|
}
|
|
26
62
|
setupInterceptors() {
|
|
63
|
+
this.client.interceptors.request.use(
|
|
64
|
+
(config) => {
|
|
65
|
+
if (config.data && !(config.data instanceof FormData)) {
|
|
66
|
+
config.data = snakeCaseKeys(config.data);
|
|
67
|
+
}
|
|
68
|
+
if (config.params) {
|
|
69
|
+
config.params = snakeCaseKeys(config.params);
|
|
70
|
+
}
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
);
|
|
27
74
|
this.client.interceptors.response.use(
|
|
28
|
-
(response) =>
|
|
75
|
+
(response) => {
|
|
76
|
+
if (response.data) {
|
|
77
|
+
response.data = camelCaseKeys(response.data);
|
|
78
|
+
}
|
|
79
|
+
return response;
|
|
80
|
+
},
|
|
29
81
|
(error) => {
|
|
30
82
|
const message = error.response?.data?.message ?? error.message ?? "Unknown error";
|
|
31
83
|
return Promise.reject({
|
|
@@ -76,10 +128,14 @@ var HttpClient = class {
|
|
|
76
128
|
return formData;
|
|
77
129
|
}
|
|
78
130
|
prepareRequest(body, config) {
|
|
79
|
-
|
|
80
|
-
|
|
131
|
+
let finalBody = body;
|
|
132
|
+
if (finalBody && typeof finalBody === "object" && !(finalBody instanceof FormData)) {
|
|
133
|
+
finalBody = snakeCaseKeys(finalBody);
|
|
134
|
+
}
|
|
135
|
+
if (!finalBody || !this.hasFiles(finalBody)) {
|
|
136
|
+
return { processedBody: finalBody, processedConfig: config };
|
|
81
137
|
}
|
|
82
|
-
const formData = this.toFormData(
|
|
138
|
+
const formData = this.toFormData(finalBody);
|
|
83
139
|
const newConfig = { ...config };
|
|
84
140
|
if (!newConfig.headers) {
|
|
85
141
|
newConfig.headers = {};
|