@gct-paas/api 0.1.2-dev.0 → 0.1.2-dev.1
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/index.esm.min.js +1 -1
- package/dist/index.system.min.js +1 -1
- package/es/service/api-manage.mjs +2 -2
- package/es/service/api-service.mjs +16 -16
- package/es/utils/index.d.ts +7 -0
- package/es/utils/index.mjs +6 -0
- package/lib/service/api-manage.cjs +2 -3
- package/lib/service/api-service.cjs +16 -17
- package/lib/utils/index.cjs +7 -0
- package/package.json +4 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { joinPath } from "../utils/index.mjs";
|
|
2
2
|
import { ApiService } from "./api-service.mjs";
|
|
3
3
|
export class ApiManage {
|
|
4
4
|
/**
|
|
@@ -18,7 +18,7 @@ export class ApiManage {
|
|
|
18
18
|
}
|
|
19
19
|
if (!(property in manage)) {
|
|
20
20
|
manage[property] = new ApiService(
|
|
21
|
-
|
|
21
|
+
joinPath(url, config.entityName),
|
|
22
22
|
config
|
|
23
23
|
);
|
|
24
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { joinPath } from "../utils/index.mjs";
|
|
2
2
|
import { HttpUtil } from "./http.util.mjs";
|
|
3
3
|
export class ApiService {
|
|
4
4
|
/**
|
|
@@ -18,22 +18,22 @@ export class ApiService {
|
|
|
18
18
|
if (cfg) {
|
|
19
19
|
const modeFn = `_${cfg.mode}`;
|
|
20
20
|
if (cfg.hasPathParams && cfg.hasData && cfg.hasQuery) {
|
|
21
|
-
api[property] = (
|
|
22
|
-
return api[modeFn](cfg.path,
|
|
21
|
+
api[property] = (path, query, data, config2) => {
|
|
22
|
+
return api[modeFn](cfg.path, path, query, data, config2);
|
|
23
23
|
};
|
|
24
24
|
} else if (cfg.hasPathParams && cfg.hasData) {
|
|
25
|
-
api[property] = function(
|
|
26
|
-
return api[modeFn](cfg.path,
|
|
25
|
+
api[property] = function(path, data, config2) {
|
|
26
|
+
return api[modeFn](cfg.path, path, void 0, data, config2);
|
|
27
27
|
};
|
|
28
28
|
} else if (cfg.hasPathParams && cfg.hasQuery) {
|
|
29
|
-
api[property] = function(
|
|
30
|
-
return api[modeFn](cfg.path,
|
|
29
|
+
api[property] = function(path, query, config2) {
|
|
30
|
+
return api[modeFn](cfg.path, path, query, void 0, config2);
|
|
31
31
|
};
|
|
32
32
|
} else if (cfg.hasPathParams) {
|
|
33
|
-
api[property] = function(
|
|
33
|
+
api[property] = function(path, config2) {
|
|
34
34
|
return api[modeFn](
|
|
35
35
|
cfg.path,
|
|
36
|
-
|
|
36
|
+
path,
|
|
37
37
|
void 0,
|
|
38
38
|
void 0,
|
|
39
39
|
config2
|
|
@@ -93,7 +93,7 @@ export class ApiService {
|
|
|
93
93
|
*/
|
|
94
94
|
_put(method, pathParams, query, data, config) {
|
|
95
95
|
return HttpUtil.put(
|
|
96
|
-
|
|
96
|
+
joinPath(this.url, method),
|
|
97
97
|
pathParams,
|
|
98
98
|
data,
|
|
99
99
|
query,
|
|
@@ -113,7 +113,7 @@ export class ApiService {
|
|
|
113
113
|
*/
|
|
114
114
|
_get(method, pathParams, query, data, config) {
|
|
115
115
|
return HttpUtil.get(
|
|
116
|
-
|
|
116
|
+
joinPath(this.url, method),
|
|
117
117
|
pathParams,
|
|
118
118
|
data,
|
|
119
119
|
query,
|
|
@@ -133,7 +133,7 @@ export class ApiService {
|
|
|
133
133
|
*/
|
|
134
134
|
_delete(method, pathParams, query, data, config) {
|
|
135
135
|
return HttpUtil.delete(
|
|
136
|
-
|
|
136
|
+
joinPath(this.url, method),
|
|
137
137
|
pathParams,
|
|
138
138
|
data,
|
|
139
139
|
query,
|
|
@@ -153,7 +153,7 @@ export class ApiService {
|
|
|
153
153
|
*/
|
|
154
154
|
_post(method, pathParams, query, data, config) {
|
|
155
155
|
return HttpUtil.post(
|
|
156
|
-
|
|
156
|
+
joinPath(this.url, method),
|
|
157
157
|
pathParams,
|
|
158
158
|
data,
|
|
159
159
|
query,
|
|
@@ -173,7 +173,7 @@ export class ApiService {
|
|
|
173
173
|
*/
|
|
174
174
|
_options(method, pathParams, query, data, config) {
|
|
175
175
|
return HttpUtil.options(
|
|
176
|
-
|
|
176
|
+
joinPath(this.url, method),
|
|
177
177
|
pathParams,
|
|
178
178
|
data,
|
|
179
179
|
query,
|
|
@@ -193,7 +193,7 @@ export class ApiService {
|
|
|
193
193
|
*/
|
|
194
194
|
_patch(method, pathParams, query, data, config) {
|
|
195
195
|
return HttpUtil.patch(
|
|
196
|
-
|
|
196
|
+
joinPath(this.url, method),
|
|
197
197
|
pathParams,
|
|
198
198
|
data,
|
|
199
199
|
query,
|
|
@@ -213,7 +213,7 @@ export class ApiService {
|
|
|
213
213
|
*/
|
|
214
214
|
_head(method, pathParams, query, data, config) {
|
|
215
215
|
return HttpUtil.head(
|
|
216
|
-
|
|
216
|
+
joinPath(this.url, method),
|
|
217
217
|
pathParams,
|
|
218
218
|
data,
|
|
219
219
|
query,
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { cloneDeep, isEqual, mergeWith, unionWith } from "lodash-es";
|
|
2
|
+
export function joinPath(...segments) {
|
|
3
|
+
return segments.map((seg, i) => {
|
|
4
|
+
if (i === 0) return seg.replace(/\/+$/, "");
|
|
5
|
+
return seg.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
6
|
+
}).filter(Boolean).join("/");
|
|
7
|
+
}
|
|
2
8
|
export function deepMerge(target, source) {
|
|
3
9
|
return mergeWith(cloneDeep(target), source, (objValue, srcValue) => {
|
|
4
10
|
if (typeof objValue === "object" && typeof srcValue === "object") {
|
|
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ApiManage = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _utils = require("../utils/index.cjs");
|
|
8
8
|
var _apiService = require("./api-service.cjs");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
class ApiManage {
|
|
11
10
|
/**
|
|
12
11
|
* 根据 api 配置挂载请求对象以及方法
|
|
@@ -24,7 +23,7 @@ class ApiManage {
|
|
|
24
23
|
return void 0;
|
|
25
24
|
}
|
|
26
25
|
if (!(property in manage)) {
|
|
27
|
-
manage[property] = new _apiService.ApiService(
|
|
26
|
+
manage[property] = new _apiService.ApiService((0, _utils.joinPath)(url, config.entityName), config);
|
|
28
27
|
}
|
|
29
28
|
return manage[property];
|
|
30
29
|
}
|
|
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ApiService = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _utils = require("../utils/index.cjs");
|
|
8
8
|
var _http = require("./http.util.cjs");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
9
|
class ApiService {
|
|
11
10
|
/**
|
|
12
11
|
* Creates an instance of ApiService.
|
|
@@ -25,20 +24,20 @@ class ApiService {
|
|
|
25
24
|
if (cfg) {
|
|
26
25
|
const modeFn = `_${cfg.mode}`;
|
|
27
26
|
if (cfg.hasPathParams && cfg.hasData && cfg.hasQuery) {
|
|
28
|
-
api[property] = (
|
|
29
|
-
return api[modeFn](cfg.path,
|
|
27
|
+
api[property] = (path, query, data, config2) => {
|
|
28
|
+
return api[modeFn](cfg.path, path, query, data, config2);
|
|
30
29
|
};
|
|
31
30
|
} else if (cfg.hasPathParams && cfg.hasData) {
|
|
32
|
-
api[property] = function (
|
|
33
|
-
return api[modeFn](cfg.path,
|
|
31
|
+
api[property] = function (path, data, config2) {
|
|
32
|
+
return api[modeFn](cfg.path, path, void 0, data, config2);
|
|
34
33
|
};
|
|
35
34
|
} else if (cfg.hasPathParams && cfg.hasQuery) {
|
|
36
|
-
api[property] = function (
|
|
37
|
-
return api[modeFn](cfg.path,
|
|
35
|
+
api[property] = function (path, query, config2) {
|
|
36
|
+
return api[modeFn](cfg.path, path, query, void 0, config2);
|
|
38
37
|
};
|
|
39
38
|
} else if (cfg.hasPathParams) {
|
|
40
|
-
api[property] = function (
|
|
41
|
-
return api[modeFn](cfg.path,
|
|
39
|
+
api[property] = function (path, config2) {
|
|
40
|
+
return api[modeFn](cfg.path, path, void 0, void 0, config2);
|
|
42
41
|
};
|
|
43
42
|
} else if (cfg.hasData && cfg.hasQuery) {
|
|
44
43
|
api[property] = function (query, data, config2) {
|
|
@@ -75,7 +74,7 @@ class ApiService {
|
|
|
75
74
|
* @returns {Promise<T>} 请求结果
|
|
76
75
|
*/
|
|
77
76
|
_put(method, pathParams, query, data, config) {
|
|
78
|
-
return _http.HttpUtil.put(
|
|
77
|
+
return _http.HttpUtil.put((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
79
78
|
}
|
|
80
79
|
/**
|
|
81
80
|
* GET 请求方法
|
|
@@ -89,7 +88,7 @@ class ApiService {
|
|
|
89
88
|
* @returns {Promise<T>} 请求结果
|
|
90
89
|
*/
|
|
91
90
|
_get(method, pathParams, query, data, config) {
|
|
92
|
-
return _http.HttpUtil.get(
|
|
91
|
+
return _http.HttpUtil.get((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
93
92
|
}
|
|
94
93
|
/**
|
|
95
94
|
* DELETE 请求方法
|
|
@@ -103,7 +102,7 @@ class ApiService {
|
|
|
103
102
|
* @returns {Promise<T>} 请求结果
|
|
104
103
|
*/
|
|
105
104
|
_delete(method, pathParams, query, data, config) {
|
|
106
|
-
return _http.HttpUtil.delete(
|
|
105
|
+
return _http.HttpUtil.delete((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
107
106
|
}
|
|
108
107
|
/**
|
|
109
108
|
* POST 请求方法
|
|
@@ -117,7 +116,7 @@ class ApiService {
|
|
|
117
116
|
* @returns {Promise<T>} 请求结果
|
|
118
117
|
*/
|
|
119
118
|
_post(method, pathParams, query, data, config) {
|
|
120
|
-
return _http.HttpUtil.post(
|
|
119
|
+
return _http.HttpUtil.post((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
121
120
|
}
|
|
122
121
|
/**
|
|
123
122
|
* OPTIONS 请求方法
|
|
@@ -131,7 +130,7 @@ class ApiService {
|
|
|
131
130
|
* @returns {Promise<T>} 请求结果
|
|
132
131
|
*/
|
|
133
132
|
_options(method, pathParams, query, data, config) {
|
|
134
|
-
return _http.HttpUtil.options(
|
|
133
|
+
return _http.HttpUtil.options((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
135
134
|
}
|
|
136
135
|
/**
|
|
137
136
|
* PATCH 请求方法
|
|
@@ -145,7 +144,7 @@ class ApiService {
|
|
|
145
144
|
* @returns {Promise<T>} 请求结果
|
|
146
145
|
*/
|
|
147
146
|
_patch(method, pathParams, query, data, config) {
|
|
148
|
-
return _http.HttpUtil.patch(
|
|
147
|
+
return _http.HttpUtil.patch((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
149
148
|
}
|
|
150
149
|
/**
|
|
151
150
|
* HEAD 请求方法
|
|
@@ -159,7 +158,7 @@ class ApiService {
|
|
|
159
158
|
* @returns {Promise<T>} 请求结果
|
|
160
159
|
*/
|
|
161
160
|
_head(method, pathParams, query, data, config) {
|
|
162
|
-
return _http.HttpUtil.head(
|
|
161
|
+
return _http.HttpUtil.head((0, _utils.joinPath)(this.url, method), pathParams, data, query, config);
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
164
|
exports.ApiService = ApiService;
|
package/lib/utils/index.cjs
CHANGED
|
@@ -4,7 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deepMerge = deepMerge;
|
|
7
|
+
exports.joinPath = joinPath;
|
|
7
8
|
var _lodashEs = require("lodash-es");
|
|
9
|
+
function joinPath(...segments) {
|
|
10
|
+
return segments.map((seg, i) => {
|
|
11
|
+
if (i === 0) return seg.replace(/\/+$/, "");
|
|
12
|
+
return seg.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
13
|
+
}).filter(Boolean).join("/");
|
|
14
|
+
}
|
|
8
15
|
function deepMerge(target, source) {
|
|
9
16
|
return (0, _lodashEs.mergeWith)((0, _lodashEs.cloneDeep)(target), source, (objValue, srcValue) => {
|
|
10
17
|
if (typeof objValue === "object" && typeof srcValue === "object") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/api",
|
|
3
|
-
"version": "0.1.2-dev.
|
|
3
|
+
"version": "0.1.2-dev.1",
|
|
4
4
|
"description": "paas 平台底包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"types": "./es/index.d.ts",
|
|
21
21
|
"main": "./lib/index.cjs",
|
|
22
22
|
"module": "./es/index.mjs",
|
|
23
|
+
"loader": "./dist/index.esm.min.js",
|
|
23
24
|
"exports": {
|
|
24
25
|
".": {
|
|
25
26
|
"types": "./es/index.d.ts",
|
|
@@ -71,7 +72,6 @@
|
|
|
71
72
|
"dependencies": {
|
|
72
73
|
"axios": "^1.13.2",
|
|
73
74
|
"lodash-es": "^4.17.23",
|
|
74
|
-
"path-browserify": "^1.0.1",
|
|
75
75
|
"qs": "^6.14.1"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@babel/preset-env": "^7.28.6",
|
|
82
82
|
"@commitlint/cli": "^20.3.1",
|
|
83
|
-
"@gct-paas/build": "^0.1.
|
|
84
|
-
"@gct-paas/cli": "0.1.
|
|
83
|
+
"@gct-paas/build": "^0.1.6-dev.6",
|
|
84
|
+
"@gct-paas/cli": "^0.1.6-dev.6",
|
|
85
85
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
86
86
|
"@rollup/plugin-json": "^6.1.0",
|
|
87
87
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
@@ -89,7 +89,6 @@
|
|
|
89
89
|
"@types/fs-extra": "^11.0.4",
|
|
90
90
|
"@types/lodash-es": "^4.17.12",
|
|
91
91
|
"@types/node": "^25.0.10",
|
|
92
|
-
"@types/path-browserify": "^1.0.3",
|
|
93
92
|
"@types/qs": "^6.14.0",
|
|
94
93
|
"@types/systemjs": "^6.15.4",
|
|
95
94
|
"@vue/tsconfig": "^0.8.1",
|