moyan-api 1.0.56 → 1.0.63
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/CHANGELOG.md +19 -0
- package/dist/creator.d.ts +2 -2
- package/dist/creator.js +22 -22
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/lib/base.d.ts +66 -67
- package/dist/lib/base.js +153 -153
- package/dist/lib/base.js.map +1 -1
- package/dist/main.d.ts +22 -22
- package/dist/main.js +87 -87
- package/dist/main.js.map +1 -1
- package/dist/program.d.ts +12 -12
- package/dist/program.js +12 -12
- package/dist/template/api.d.ts +18 -18
- package/dist/template/api.js +106 -106
- package/dist/template/api.js.map +1 -1
- package/dist/template/schemas.d.ts +13 -13
- package/dist/template/schemas.js +92 -92
- package/dist/template/schemas.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/mo.d.ts +28 -28
- package/dist/utils/mo.js +253 -253
- package/dist/utils/mo.js.map +1 -1
- package/package.json +9 -9
- package/view/api.ejs +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.0.63](https://gitee.com/ymoo/moyan-api/compare/v1.0.62...v1.0.63) (2025-12-12)
|
|
6
|
+
|
|
7
|
+
### [1.0.62](https://gitee.com/ymoo/moyan-api/compare/v1.0.61...v1.0.62) (2025-12-12)
|
|
8
|
+
|
|
9
|
+
### [1.0.61](https://gitee.com/ymoo/moyan-api/compare/v1.0.60...v1.0.61) (2025-12-11)
|
|
10
|
+
|
|
11
|
+
### [1.0.60](https://gitee.com/ymoo/moyan-api/compare/v1.0.59...v1.0.60) (2025-12-11)
|
|
12
|
+
|
|
13
|
+
### [1.0.59](https://gitee.com/ymoo/moyan-api/compare/v1.0.58...v1.0.59) (2025-12-11)
|
|
14
|
+
|
|
15
|
+
### [1.0.58](https://gitee.com/ymoo/moyan-api/compare/v1.0.57...v1.0.58) (2025-12-11)
|
|
16
|
+
|
|
17
|
+
### [1.0.57](https://gitee.com/ymoo/moyan-api/compare/v1.0.56...v1.0.57) (2025-12-11)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* 修复类型声明和接口定义问题 ([06f6ddd](https://gitee.com/ymoo/moyan-api/commit/06f6ddd5a033da4f72088c446fc5c5fb6c59a47e))
|
|
23
|
+
|
|
5
24
|
### [1.0.56](https://gitee.com/ymoo/moyan-api/compare/v1.0.55...v1.0.56) (2025-09-16)
|
|
6
25
|
|
|
7
26
|
### [1.0.55](https://gitee.com/ymoo/moyan-api/compare/v1.0.54...v1.0.55) (2025-09-16)
|
package/dist/creator.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import 'colors';
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'colors';
|
package/dist/creator.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const commander_1 = require("commander");
|
|
5
|
-
require("colors");
|
|
6
|
-
const main_1 = require("./main");
|
|
7
|
-
commander_1.program
|
|
8
|
-
.version(require('../package').version)
|
|
9
|
-
.option('-a, --apijson [apijson]', 'openApi json 文件路径')
|
|
10
|
-
.option('-o, --output [output]', '输出路径')
|
|
11
|
-
.option('-d, --dirname [dirname]', '生成的sdk目录名')
|
|
12
|
-
.option('-j, --jsonurl [jsonurl]', '远程openApi 地址')
|
|
13
|
-
.option('-af, --apiprefix [apiprefix]', '生成的skd 类名前缀')
|
|
14
|
-
.option('-pp, --pathprefix [pathprefix]', '添加的路径请求前缀')
|
|
15
|
-
.parse(process.argv);
|
|
16
|
-
console.info('生成 openApi 3.0 调用SDK... ');
|
|
17
|
-
console.log('apijson', commander_1.program.getOptionValue('apijson'));
|
|
18
|
-
console.log('output', commander_1.program.getOptionValue('output'));
|
|
19
|
-
console.log('jsonurl', commander_1.program.getOptionValue('jsonurl'));
|
|
20
|
-
console.log('apiprefix', commander_1.program.getOptionValue('apiprefix'));
|
|
21
|
-
console.log('pathprefix', commander_1.program.getOptionValue('pathprefix'));
|
|
22
|
-
new main_1.ApisdkCreator(commander_1.program).create();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
require("colors");
|
|
6
|
+
const main_1 = require("./main");
|
|
7
|
+
commander_1.program
|
|
8
|
+
.version(require('../package').version)
|
|
9
|
+
.option('-a, --apijson [apijson]', 'openApi json 文件路径')
|
|
10
|
+
.option('-o, --output [output]', '输出路径')
|
|
11
|
+
.option('-d, --dirname [dirname]', '生成的sdk目录名')
|
|
12
|
+
.option('-j, --jsonurl [jsonurl]', '远程openApi 地址')
|
|
13
|
+
.option('-af, --apiprefix [apiprefix]', '生成的skd 类名前缀')
|
|
14
|
+
.option('-pp, --pathprefix [pathprefix]', '添加的路径请求前缀')
|
|
15
|
+
.parse(process.argv);
|
|
16
|
+
console.info('生成 openApi 3.0 调用SDK... ');
|
|
17
|
+
console.log('apijson', commander_1.program.getOptionValue('apijson'));
|
|
18
|
+
console.log('output', commander_1.program.getOptionValue('output'));
|
|
19
|
+
console.log('jsonurl', commander_1.program.getOptionValue('jsonurl'));
|
|
20
|
+
console.log('apiprefix', commander_1.program.getOptionValue('apiprefix'));
|
|
21
|
+
console.log('pathprefix', commander_1.program.getOptionValue('pathprefix'));
|
|
22
|
+
new main_1.ApisdkCreator(commander_1.program).create();
|
|
23
23
|
//# sourceMappingURL=creator.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ApiCall, ApiEntity, ApiCallProps, SubApiEntity, ObjectAny, Option, MoMethod } from './lib/base';
|
|
2
|
-
export { ApiCall, ApiEntity, ApiCallProps, SubApiEntity, ObjectAny, Option, MoMethod };
|
|
1
|
+
import { ApiCall, ApiEntity, ApiCallProps, SubApiEntity, ObjectAny, Option, MoMethod } from './lib/base';
|
|
2
|
+
export { ApiCall, ApiEntity, ApiCallProps, SubApiEntity, ObjectAny, Option, MoMethod };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiCall = void 0;
|
|
4
|
-
const base_1 = require("./lib/base");
|
|
5
|
-
Object.defineProperty(exports, "ApiCall", { enumerable: true, get: function () { return base_1.ApiCall; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiCall = void 0;
|
|
4
|
+
const base_1 = require("./lib/base");
|
|
5
|
+
Object.defineProperty(exports, "ApiCall", { enumerable: true, get: function () { return base_1.ApiCall; } });
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/base.d.ts
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
static
|
|
37
|
-
static
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
static
|
|
47
|
-
static
|
|
48
|
-
static
|
|
49
|
-
|
|
50
|
-
abstract
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
get
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
get
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
export type MoMethod = "POST" | "GET" | "DELETE" | "PUT" | "ALL";
|
|
3
|
+
export interface ObjectAny {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export interface Option {
|
|
7
|
+
fileName?: string;
|
|
8
|
+
prefix?: boolean;
|
|
9
|
+
hintSuccess?: boolean;
|
|
10
|
+
hintFail?: boolean;
|
|
11
|
+
showLoading?: boolean;
|
|
12
|
+
successMsg?: ((res: any) => string) | string | null;
|
|
13
|
+
failMsg?: ((err: any) => string) | string | null;
|
|
14
|
+
loading?: boolean;
|
|
15
|
+
ext?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
export interface ApiCallProps<T> {
|
|
18
|
+
params?: T;
|
|
19
|
+
query?: Record<string, string | number>;
|
|
20
|
+
option?: Option | {};
|
|
21
|
+
}
|
|
22
|
+
export declare abstract class RequestClass {
|
|
23
|
+
abstract request(apiEntity: ApiEntity): Promise<any>;
|
|
24
|
+
}
|
|
25
|
+
export interface SubApiEntity extends RequestClass {
|
|
26
|
+
}
|
|
27
|
+
export declare enum ApiEvents {
|
|
28
|
+
HintSuccess = "hintSuccess",
|
|
29
|
+
Success = "success",
|
|
30
|
+
HintFail = "hintFail",
|
|
31
|
+
Unauthorized = "unauthorized",
|
|
32
|
+
Fail = "fail"
|
|
33
|
+
}
|
|
34
|
+
export declare abstract class ApiCall<ReqType, ResType> extends Promise<any> {
|
|
35
|
+
static MoCall: SubApiEntity;
|
|
36
|
+
static use(moCall: SubApiEntity): void;
|
|
37
|
+
static hasPrompted: boolean;
|
|
38
|
+
params: ReqType | {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
};
|
|
41
|
+
result: ResType & {
|
|
42
|
+
message?: string;
|
|
43
|
+
};
|
|
44
|
+
option: Option;
|
|
45
|
+
static hintSuccessHandler: (result: ApiCall<any, any>) => void;
|
|
46
|
+
static hintFailHandler: (err: ApiCall<any, any>) => void;
|
|
47
|
+
static handler401: (err: ApiCall<any, any>) => void;
|
|
48
|
+
static emitter: EventEmitter<any>;
|
|
49
|
+
abstract path: string;
|
|
50
|
+
abstract method: MoMethod;
|
|
51
|
+
error: any;
|
|
52
|
+
query: Record<string, string | number>;
|
|
53
|
+
get status(): any;
|
|
54
|
+
get statusCode(): any;
|
|
55
|
+
response: any;
|
|
56
|
+
resolve: (result: ApiCall<ReqType, ResType>["result"]) => void;
|
|
57
|
+
reject: (err: any) => void;
|
|
58
|
+
get successMsg(): string;
|
|
59
|
+
get failMsg(): any;
|
|
60
|
+
constructor(props?: ApiCallProps<ReqType>);
|
|
61
|
+
replaceUrlParams<T extends Record<string, string | number>>(urlTemplate: string, params: T): string;
|
|
62
|
+
init(props?: ApiCallProps<ReqType>): void;
|
|
63
|
+
exec(): void;
|
|
64
|
+
}
|
|
65
|
+
export interface ApiEntity extends ApiCall<any, any> {
|
|
66
|
+
}
|
package/dist/lib/base.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiCall = exports.ApiEvents = exports.RequestClass = void 0;
|
|
4
|
-
const events_1 = require("events");
|
|
5
|
-
class RequestClass {
|
|
6
|
-
}
|
|
7
|
-
exports.RequestClass = RequestClass;
|
|
8
|
-
var ApiEvents;
|
|
9
|
-
(function (ApiEvents) {
|
|
10
|
-
ApiEvents["HintSuccess"] = "hintSuccess";
|
|
11
|
-
ApiEvents["Success"] = "success";
|
|
12
|
-
ApiEvents["HintFail"] = "hintFail";
|
|
13
|
-
ApiEvents["Unauthorized"] = "unauthorized";
|
|
14
|
-
ApiEvents["Fail"] = "fail";
|
|
15
|
-
})(ApiEvents
|
|
16
|
-
class ApiCall extends Promise {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
replaceUrlParams(urlTemplate, params) {
|
|
85
|
-
return urlTemplate.replace(/\{(\w+)\}/g, (match, paramName) => {
|
|
86
|
-
const value = params[paramName];
|
|
87
|
-
if (value === undefined) {
|
|
88
|
-
throw new Error(`Missing required parameter: ${paramName}`);
|
|
89
|
-
}
|
|
90
|
-
return String(value);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
init(props) {
|
|
94
|
-
const defaultOption = {
|
|
95
|
-
prefix: true,
|
|
96
|
-
hintSuccess: false,
|
|
97
|
-
hintFail: true,
|
|
98
|
-
showLoading: true,
|
|
99
|
-
loading: false,
|
|
100
|
-
successMsg: res => {
|
|
101
|
-
return res.message || "请求成功";
|
|
102
|
-
},
|
|
103
|
-
failMsg: err => {
|
|
104
|
-
return err.message;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
this.query = (props === null || props === void 0 ? void 0 : props.query) || {};
|
|
108
|
-
this.option = this.option || {};
|
|
109
|
-
if (props && typeof props.option === "object") {
|
|
110
|
-
const option = Object.assign(defaultOption, this.option, props.option);
|
|
111
|
-
Object.assign(props.option, option);
|
|
112
|
-
this.option = props.option;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
this.option = Object.assign(defaultOption, this.option);
|
|
116
|
-
}
|
|
117
|
-
this.params = props && props.params ? props.params : {};
|
|
118
|
-
}
|
|
119
|
-
exec() {
|
|
120
|
-
this.path = this.replaceUrlParams(this.path, this.query);
|
|
121
|
-
ApiCall.MoCall.request(this)
|
|
122
|
-
.then(response => {
|
|
123
|
-
this.result = response.data;
|
|
124
|
-
this.response = response;
|
|
125
|
-
if (this.option.hintSuccess && !ApiCall.hasPrompted) {
|
|
126
|
-
ApiCall.hintSuccessHandler(this);
|
|
127
|
-
ApiCall.emitter.emit(ApiEvents.HintSuccess, this);
|
|
128
|
-
}
|
|
129
|
-
ApiCall.emitter.emit(ApiEvents.Success, this);
|
|
130
|
-
this.resolve(response.data);
|
|
131
|
-
})
|
|
132
|
-
.catch(err => {
|
|
133
|
-
this.error = err;
|
|
134
|
-
this.response = err.response || {};
|
|
135
|
-
if (this.option.hintFail && !ApiCall.hasPrompted) {
|
|
136
|
-
ApiCall.hintFailHandler(this);
|
|
137
|
-
ApiCall.emitter.emit(ApiEvents.HintFail, this);
|
|
138
|
-
}
|
|
139
|
-
if (this.status === 401) {
|
|
140
|
-
ApiCall.handler401(this);
|
|
141
|
-
ApiCall.emitter.emit(ApiEvents.Unauthorized, this);
|
|
142
|
-
}
|
|
143
|
-
ApiCall.emitter.emit(ApiEvents.Fail, this);
|
|
144
|
-
this.reject(err);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.ApiCall = ApiCall;
|
|
149
|
-
ApiCall.hasPrompted = false;
|
|
150
|
-
ApiCall.hintSuccessHandler = (result) => { };
|
|
151
|
-
ApiCall.hintFailHandler = (err) => { };
|
|
152
|
-
ApiCall.handler401 = (err) => { };
|
|
153
|
-
ApiCall.emitter = new events_1.EventEmitter();
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiCall = exports.ApiEvents = exports.RequestClass = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class RequestClass {
|
|
6
|
+
}
|
|
7
|
+
exports.RequestClass = RequestClass;
|
|
8
|
+
var ApiEvents;
|
|
9
|
+
(function (ApiEvents) {
|
|
10
|
+
ApiEvents["HintSuccess"] = "hintSuccess";
|
|
11
|
+
ApiEvents["Success"] = "success";
|
|
12
|
+
ApiEvents["HintFail"] = "hintFail";
|
|
13
|
+
ApiEvents["Unauthorized"] = "unauthorized";
|
|
14
|
+
ApiEvents["Fail"] = "fail";
|
|
15
|
+
})(ApiEvents || (exports.ApiEvents = ApiEvents = {}));
|
|
16
|
+
class ApiCall extends Promise {
|
|
17
|
+
static use(moCall) {
|
|
18
|
+
ApiCall.MoCall = moCall;
|
|
19
|
+
}
|
|
20
|
+
get status() {
|
|
21
|
+
try {
|
|
22
|
+
return this.response.status;
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
get statusCode() {
|
|
29
|
+
try {
|
|
30
|
+
try {
|
|
31
|
+
this.response.data.statusCode;
|
|
32
|
+
}
|
|
33
|
+
catch (_a) {
|
|
34
|
+
return this.response.status;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (_b) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get successMsg() {
|
|
42
|
+
if (typeof this.option.successMsg === "string") {
|
|
43
|
+
return this.option.successMsg;
|
|
44
|
+
}
|
|
45
|
+
else if (typeof this.option.successMsg === "function") {
|
|
46
|
+
return this.option.successMsg(this.result);
|
|
47
|
+
}
|
|
48
|
+
else if (this.result["message"]) {
|
|
49
|
+
return this.result["message"];
|
|
50
|
+
}
|
|
51
|
+
return "请求成功";
|
|
52
|
+
}
|
|
53
|
+
get failMsg() {
|
|
54
|
+
if (this.error) {
|
|
55
|
+
if (typeof this.option.failMsg === "string") {
|
|
56
|
+
return this.option.failMsg;
|
|
57
|
+
}
|
|
58
|
+
else if (typeof this.option.failMsg === "function") {
|
|
59
|
+
return this.option.failMsg(this.error);
|
|
60
|
+
}
|
|
61
|
+
return this.error.message || this.error.data
|
|
62
|
+
? this.error.data.mssage
|
|
63
|
+
: "请求错误";
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
constructor(props) {
|
|
68
|
+
if (typeof props === "function") {
|
|
69
|
+
super(props);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const slef = {};
|
|
73
|
+
super((resolve, reject) => {
|
|
74
|
+
slef.resolve = resolve;
|
|
75
|
+
slef.reject = reject;
|
|
76
|
+
});
|
|
77
|
+
Object.assign(this, slef);
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
this.init(props);
|
|
80
|
+
this.exec();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
replaceUrlParams(urlTemplate, params) {
|
|
85
|
+
return urlTemplate.replace(/\{(\w+)\}/g, (match, paramName) => {
|
|
86
|
+
const value = params[paramName];
|
|
87
|
+
if (value === undefined) {
|
|
88
|
+
throw new Error(`Missing required parameter: ${paramName}`);
|
|
89
|
+
}
|
|
90
|
+
return String(value);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
init(props) {
|
|
94
|
+
const defaultOption = {
|
|
95
|
+
prefix: true,
|
|
96
|
+
hintSuccess: false,
|
|
97
|
+
hintFail: true,
|
|
98
|
+
showLoading: true,
|
|
99
|
+
loading: false,
|
|
100
|
+
successMsg: res => {
|
|
101
|
+
return res.message || "请求成功";
|
|
102
|
+
},
|
|
103
|
+
failMsg: err => {
|
|
104
|
+
return err.message;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
this.query = (props === null || props === void 0 ? void 0 : props.query) || {};
|
|
108
|
+
this.option = this.option || {};
|
|
109
|
+
if (props && typeof props.option === "object") {
|
|
110
|
+
const option = Object.assign(defaultOption, this.option, props.option);
|
|
111
|
+
Object.assign(props.option, option);
|
|
112
|
+
this.option = props.option;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.option = Object.assign(defaultOption, this.option);
|
|
116
|
+
}
|
|
117
|
+
this.params = props && props.params ? props.params : {};
|
|
118
|
+
}
|
|
119
|
+
exec() {
|
|
120
|
+
this.path = this.replaceUrlParams(this.path, this.query);
|
|
121
|
+
ApiCall.MoCall.request(this)
|
|
122
|
+
.then(response => {
|
|
123
|
+
this.result = response.data;
|
|
124
|
+
this.response = response;
|
|
125
|
+
if (this.option.hintSuccess && !ApiCall.hasPrompted) {
|
|
126
|
+
ApiCall.hintSuccessHandler(this);
|
|
127
|
+
ApiCall.emitter.emit(ApiEvents.HintSuccess, this);
|
|
128
|
+
}
|
|
129
|
+
ApiCall.emitter.emit(ApiEvents.Success, this);
|
|
130
|
+
this.resolve(response.data);
|
|
131
|
+
})
|
|
132
|
+
.catch(err => {
|
|
133
|
+
this.error = err;
|
|
134
|
+
this.response = err.response || {};
|
|
135
|
+
if (this.option.hintFail && !ApiCall.hasPrompted) {
|
|
136
|
+
ApiCall.hintFailHandler(this);
|
|
137
|
+
ApiCall.emitter.emit(ApiEvents.HintFail, this);
|
|
138
|
+
}
|
|
139
|
+
if (this.status === 401) {
|
|
140
|
+
ApiCall.handler401(this);
|
|
141
|
+
ApiCall.emitter.emit(ApiEvents.Unauthorized, this);
|
|
142
|
+
}
|
|
143
|
+
ApiCall.emitter.emit(ApiEvents.Fail, this);
|
|
144
|
+
this.reject(err);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.ApiCall = ApiCall;
|
|
149
|
+
ApiCall.hasPrompted = false;
|
|
150
|
+
ApiCall.hintSuccessHandler = (result) => { };
|
|
151
|
+
ApiCall.hintFailHandler = (err) => { };
|
|
152
|
+
ApiCall.handler401 = (err) => { };
|
|
153
|
+
ApiCall.emitter = new events_1.EventEmitter();
|
|
154
154
|
//# sourceMappingURL=base.js.map
|
package/dist/lib/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/lib/base.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAiErC,MAAsB,YAAY;CAEjC;AAFD,oCAEC;AAID,IAAY,SAMX;AAND,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,gCAAmB,CAAA;IACnB,kCAAqB,CAAA;IACrB,0CAA6B,CAAA;IAC7B,0BAAa,CAAA;AACf,CAAC,EANW,SAAS,
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/lib/base.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAiErC,MAAsB,YAAY;CAEjC;AAFD,oCAEC;AAID,IAAY,SAMX;AAND,WAAY,SAAS;IACnB,wCAA2B,CAAA;IAC3B,gCAAmB,CAAA;IACnB,kCAAqB,CAAA;IACrB,0CAA6B,CAAA;IAC7B,0BAAa,CAAA;AACf,CAAC,EANW,SAAS,yBAAT,SAAS,Q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AA;YACpD,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAC1C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;IACN,CAAC;;AAjLH,0BAkLC;AA3KQ,mBAAW,GAAG,KAAK,CAAA;AAOnB,0BAAkB,GAAG,CAAC,MAAyB,EAAE,EAAE,GAAE,CAAC,CAAA;AAEtD,uBAAe,GAAG,CAAC,GAAsB,EAAE,EAAE,GAAE,CAAC,CAAA;AAEhD,kBAAU,GAAG,CAAC,GAAsB,EAAE,EAAE,GAAE,CAAC,CAAA;AAE3C,eAAO,GAAG,IAAI,qBAAY,EAAE,CAAA"}
|
package/dist/main.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import MFManage, { SchemaManager } from "moyan-file-model";
|
|
2
|
-
import { Command } from "commander";
|
|
3
|
-
import { Program } from "./program";
|
|
4
|
-
export declare class ApisdkCreator {
|
|
5
|
-
mFManage: MFManage;
|
|
6
|
-
error: Array<any>;
|
|
7
|
-
program: Command | Program;
|
|
8
|
-
get runPath(): string;
|
|
9
|
-
get packageData(): any;
|
|
10
|
-
get outputPath(): any;
|
|
11
|
-
get openAPIObject(): any;
|
|
12
|
-
get prefix(): any;
|
|
13
|
-
get pathPrefix(): any;
|
|
14
|
-
get dirname(): any;
|
|
15
|
-
get jsonurl(): any;
|
|
16
|
-
constructor(program: Command | Program);
|
|
17
|
-
schemaManagerData: {};
|
|
18
|
-
schemaManager: SchemaManager;
|
|
19
|
-
getRemoteData(): Promise<any>;
|
|
20
|
-
init(): Promise<void>;
|
|
21
|
-
create(): Promise<any[]>;
|
|
22
|
-
}
|
|
1
|
+
import MFManage, { SchemaManager } from "moyan-file-model";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { Program } from "./program";
|
|
4
|
+
export declare class ApisdkCreator {
|
|
5
|
+
mFManage: MFManage;
|
|
6
|
+
error: Array<any>;
|
|
7
|
+
program: Command | Program;
|
|
8
|
+
get runPath(): string;
|
|
9
|
+
get packageData(): any;
|
|
10
|
+
get outputPath(): any;
|
|
11
|
+
get openAPIObject(): any;
|
|
12
|
+
get prefix(): any;
|
|
13
|
+
get pathPrefix(): any;
|
|
14
|
+
get dirname(): any;
|
|
15
|
+
get jsonurl(): any;
|
|
16
|
+
constructor(program: Command | Program);
|
|
17
|
+
schemaManagerData: {};
|
|
18
|
+
schemaManager: SchemaManager;
|
|
19
|
+
getRemoteData(): Promise<any>;
|
|
20
|
+
init(): Promise<void>;
|
|
21
|
+
create(): Promise<any[]>;
|
|
22
|
+
}
|