xpe 0.0.0-alpha.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/LICENSE +21 -0
- package/README.md +71 -0
- package/framework/es/core/Application.d.ts +126 -0
- package/framework/es/core/Command/Command.d.ts +7 -0
- package/framework/es/core/Container/Container.d.ts +80 -0
- package/framework/es/core/Contracts/AxiosAdapter.d.ts +12 -0
- package/framework/es/core/Helper/Helper.d.ts +43 -0
- package/framework/es/core/Helper/Storage/WebStorage.d.ts +71 -0
- package/framework/es/core/Libs/Exception.d.ts +24 -0
- package/framework/es/core/Libs/Lib.d.ts +72 -0
- package/framework/es/core/Provider/CommandProvider.d.ts +4 -0
- package/framework/es/core/Provider/HelperProvider.d.ts +4 -0
- package/framework/es/core/Provider/HttpProvider.d.ts +13 -0
- package/framework/es/core/Provider/ServiceProvider.d.ts +15 -0
- package/framework/es/core/Service/HttpService.d.ts +133 -0
- package/framework/es/core/Service/Service.d.ts +6 -0
- package/framework/es/core/Spanner/RESTful.d.ts +30 -0
- package/framework/es/core/Transformer/Transformer.d.ts +46 -0
- package/framework/es/core/Type/adapters.d.ts +25 -0
- package/framework/es/core/Type/types.d.ts +161 -0
- package/framework/es/core/TypeFunc/index.d.ts +6 -0
- package/framework/es/core/Wrenches/EventBus.d.ts +56 -0
- package/framework/es/core/Wrenches/is.d.ts +19 -0
- package/framework/es/ege.js +4 -0
- package/framework/es/ege.js.map +1 -0
- package/framework/es/index.d.ts +13 -0
- package/framework/es/pdd.js +4 -0
- package/framework/es/pdd.js.map +1 -0
- package/framework/es/src/core/Application.d.ts +127 -0
- package/framework/es/src/core/Application.d.ts.map +1 -0
- package/framework/es/src/core/Command/Command.d.ts +8 -0
- package/framework/es/src/core/Command/Command.d.ts.map +1 -0
- package/framework/es/src/core/Container/Container.d.ts +81 -0
- package/framework/es/src/core/Container/Container.d.ts.map +1 -0
- package/framework/es/src/core/Contracts/AxiosAdapter.d.ts +13 -0
- package/framework/es/src/core/Contracts/AxiosAdapter.d.ts.map +1 -0
- package/framework/es/src/core/Helper/Helper.d.ts +45 -0
- package/framework/es/src/core/Helper/Helper.d.ts.map +1 -0
- package/framework/es/src/core/Helper/Storage/WebStorage.d.ts +72 -0
- package/framework/es/src/core/Helper/Storage/WebStorage.d.ts.map +1 -0
- package/framework/es/src/core/Libs/Exception.d.ts +25 -0
- package/framework/es/src/core/Libs/Exception.d.ts.map +1 -0
- package/framework/es/src/core/Libs/Lib.d.ts +73 -0
- package/framework/es/src/core/Libs/Lib.d.ts.map +1 -0
- package/framework/es/src/core/Provider/CommandProvider.d.ts +5 -0
- package/framework/es/src/core/Provider/CommandProvider.d.ts.map +1 -0
- package/framework/es/src/core/Provider/HelperProvider.d.ts +5 -0
- package/framework/es/src/core/Provider/HelperProvider.d.ts.map +1 -0
- package/framework/es/src/core/Provider/HttpProvider.d.ts +14 -0
- package/framework/es/src/core/Provider/HttpProvider.d.ts.map +1 -0
- package/framework/es/src/core/Provider/ServiceProvider.d.ts +16 -0
- package/framework/es/src/core/Provider/ServiceProvider.d.ts.map +1 -0
- package/framework/es/src/core/Service/HttpService.d.ts +128 -0
- package/framework/es/src/core/Service/HttpService.d.ts.map +1 -0
- package/framework/es/src/core/Service/Service.d.ts +7 -0
- package/framework/es/src/core/Service/Service.d.ts.map +1 -0
- package/framework/es/src/core/Spanner/RESTful.d.ts +32 -0
- package/framework/es/src/core/Spanner/RESTful.d.ts.map +1 -0
- package/framework/es/src/core/Transformer/Transformer.d.ts +47 -0
- package/framework/es/src/core/Transformer/Transformer.d.ts.map +1 -0
- package/framework/es/src/core/Type/adapters.d.ts +26 -0
- package/framework/es/src/core/Type/adapters.d.ts.map +1 -0
- package/framework/es/src/core/Type/types.d.ts +186 -0
- package/framework/es/src/core/Type/types.d.ts.map +1 -0
- package/framework/es/src/core/TypeFunc/index.d.ts +8 -0
- package/framework/es/src/core/TypeFunc/index.d.ts.map +1 -0
- package/framework/es/src/core/Wrenches/EventBus.d.ts +57 -0
- package/framework/es/src/core/Wrenches/EventBus.d.ts.map +1 -0
- package/framework/es/src/core/Wrenches/is.d.ts +20 -0
- package/framework/es/src/core/Wrenches/is.d.ts.map +1 -0
- package/framework/es/src/index.d.ts +14 -0
- package/framework/es/src/index.d.ts.map +1 -0
- package/framework/es/src/utils.d.ts +17 -0
- package/framework/es/src/utils.d.ts.map +1 -0
- package/framework/es/utils.d.ts +16 -0
- package/framework/umd/core/Application.d.ts +126 -0
- package/framework/umd/core/Command/Command.d.ts +7 -0
- package/framework/umd/core/Container/Container.d.ts +80 -0
- package/framework/umd/core/Contracts/AxiosAdapter.d.ts +12 -0
- package/framework/umd/core/Helper/Helper.d.ts +43 -0
- package/framework/umd/core/Helper/Storage/WebStorage.d.ts +71 -0
- package/framework/umd/core/Libs/Exception.d.ts +24 -0
- package/framework/umd/core/Libs/Lib.d.ts +72 -0
- package/framework/umd/core/Provider/CommandProvider.d.ts +4 -0
- package/framework/umd/core/Provider/HelperProvider.d.ts +4 -0
- package/framework/umd/core/Provider/HttpProvider.d.ts +13 -0
- package/framework/umd/core/Provider/ServiceProvider.d.ts +15 -0
- package/framework/umd/core/Service/HttpService.d.ts +133 -0
- package/framework/umd/core/Service/Service.d.ts +6 -0
- package/framework/umd/core/Spanner/RESTful.d.ts +30 -0
- package/framework/umd/core/Transformer/Transformer.d.ts +46 -0
- package/framework/umd/core/Type/adapters.d.ts +25 -0
- package/framework/umd/core/Type/types.d.ts +161 -0
- package/framework/umd/core/TypeFunc/index.d.ts +6 -0
- package/framework/umd/core/Wrenches/EventBus.d.ts +56 -0
- package/framework/umd/core/Wrenches/is.d.ts +19 -0
- package/framework/umd/ege.js +4 -0
- package/framework/umd/ege.js.map +1 -0
- package/framework/umd/index.d.ts +13 -0
- package/framework/umd/pdd.js +4 -0
- package/framework/umd/pdd.js.map +1 -0
- package/framework/umd/src/core/Application.d.ts +127 -0
- package/framework/umd/src/core/Application.d.ts.map +1 -0
- package/framework/umd/src/core/Command/Command.d.ts +8 -0
- package/framework/umd/src/core/Command/Command.d.ts.map +1 -0
- package/framework/umd/src/core/Container/Container.d.ts +81 -0
- package/framework/umd/src/core/Container/Container.d.ts.map +1 -0
- package/framework/umd/src/core/Contracts/AxiosAdapter.d.ts +13 -0
- package/framework/umd/src/core/Contracts/AxiosAdapter.d.ts.map +1 -0
- package/framework/umd/src/core/Helper/Helper.d.ts +45 -0
- package/framework/umd/src/core/Helper/Helper.d.ts.map +1 -0
- package/framework/umd/src/core/Helper/Storage/WebStorage.d.ts +72 -0
- package/framework/umd/src/core/Helper/Storage/WebStorage.d.ts.map +1 -0
- package/framework/umd/src/core/Libs/Exception.d.ts +25 -0
- package/framework/umd/src/core/Libs/Exception.d.ts.map +1 -0
- package/framework/umd/src/core/Libs/Lib.d.ts +73 -0
- package/framework/umd/src/core/Libs/Lib.d.ts.map +1 -0
- package/framework/umd/src/core/Provider/CommandProvider.d.ts +5 -0
- package/framework/umd/src/core/Provider/CommandProvider.d.ts.map +1 -0
- package/framework/umd/src/core/Provider/HelperProvider.d.ts +5 -0
- package/framework/umd/src/core/Provider/HelperProvider.d.ts.map +1 -0
- package/framework/umd/src/core/Provider/HttpProvider.d.ts +14 -0
- package/framework/umd/src/core/Provider/HttpProvider.d.ts.map +1 -0
- package/framework/umd/src/core/Provider/ServiceProvider.d.ts +16 -0
- package/framework/umd/src/core/Provider/ServiceProvider.d.ts.map +1 -0
- package/framework/umd/src/core/Service/HttpService.d.ts +128 -0
- package/framework/umd/src/core/Service/HttpService.d.ts.map +1 -0
- package/framework/umd/src/core/Service/Service.d.ts +7 -0
- package/framework/umd/src/core/Service/Service.d.ts.map +1 -0
- package/framework/umd/src/core/Spanner/RESTful.d.ts +32 -0
- package/framework/umd/src/core/Spanner/RESTful.d.ts.map +1 -0
- package/framework/umd/src/core/Transformer/Transformer.d.ts +47 -0
- package/framework/umd/src/core/Transformer/Transformer.d.ts.map +1 -0
- package/framework/umd/src/core/Type/adapters.d.ts +26 -0
- package/framework/umd/src/core/Type/adapters.d.ts.map +1 -0
- package/framework/umd/src/core/Type/types.d.ts +186 -0
- package/framework/umd/src/core/Type/types.d.ts.map +1 -0
- package/framework/umd/src/core/TypeFunc/index.d.ts +8 -0
- package/framework/umd/src/core/TypeFunc/index.d.ts.map +1 -0
- package/framework/umd/src/core/Wrenches/EventBus.d.ts +57 -0
- package/framework/umd/src/core/Wrenches/EventBus.d.ts.map +1 -0
- package/framework/umd/src/core/Wrenches/is.d.ts +20 -0
- package/framework/umd/src/core/Wrenches/is.d.ts.map +1 -0
- package/framework/umd/src/index.d.ts +14 -0
- package/framework/umd/src/index.d.ts.map +1 -0
- package/framework/umd/src/utils.d.ts +17 -0
- package/framework/umd/src/utils.d.ts.map +1 -0
- package/framework/umd/utils.d.ts +16 -0
- package/index.d.ts +724 -0
- package/package.json +57 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { ClassConstructor } from '../Type/utility';
|
|
2
|
+
import type { IContainer } from '../Type/types';
|
|
3
|
+
/**
|
|
4
|
+
* Class Container
|
|
5
|
+
* 容器类
|
|
6
|
+
* @author SunnyXu <xy@ztes.com>
|
|
7
|
+
*/
|
|
8
|
+
export default class Container implements IContainer {
|
|
9
|
+
protected static instance: unknown;
|
|
10
|
+
protected instances: Map<any, any>;
|
|
11
|
+
protected bindings: Record<string, any>;
|
|
12
|
+
protected aliases: Record<string, any>;
|
|
13
|
+
/**
|
|
14
|
+
* bind 绑定实体
|
|
15
|
+
* @param {String|Array} abstract
|
|
16
|
+
* @param {*} concrete
|
|
17
|
+
*/
|
|
18
|
+
bind(abstract: string | string[], concrete: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* make 创建类的实例/获取对象 create instance/object
|
|
21
|
+
* @param abstract
|
|
22
|
+
* @param params
|
|
23
|
+
* @param shared
|
|
24
|
+
*/
|
|
25
|
+
make(abstract: string, params?: object | [], shared?: boolean): any;
|
|
26
|
+
/**
|
|
27
|
+
* makeClass 创建类
|
|
28
|
+
* @param name
|
|
29
|
+
* @param executor
|
|
30
|
+
* @param params
|
|
31
|
+
* @param shared
|
|
32
|
+
*/
|
|
33
|
+
protected makeClass(name: string, executor: ClassConstructor, params: unknown, shared?: boolean): any;
|
|
34
|
+
/**
|
|
35
|
+
* makeFunc 创建函数
|
|
36
|
+
* @param name
|
|
37
|
+
* @param executor
|
|
38
|
+
* @param params
|
|
39
|
+
* @param shared
|
|
40
|
+
* @protected
|
|
41
|
+
*/
|
|
42
|
+
protected makeFunc(name: string, executor: CallableFunction, params: unknown, shared?: boolean): any;
|
|
43
|
+
/**
|
|
44
|
+
* has as existence
|
|
45
|
+
* 是否存在标识 existence 的别名
|
|
46
|
+
* @param {String} name
|
|
47
|
+
*/
|
|
48
|
+
has(name: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* existence 存在标识
|
|
51
|
+
* @param {String} name
|
|
52
|
+
*/
|
|
53
|
+
existence(name: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* getAlias 获取别名
|
|
56
|
+
* @param abstract
|
|
57
|
+
*/
|
|
58
|
+
getAlias(abstract: string): any;
|
|
59
|
+
/**
|
|
60
|
+
* get 获取实例
|
|
61
|
+
* @param abstract
|
|
62
|
+
*/
|
|
63
|
+
get(abstract: string): any;
|
|
64
|
+
/**
|
|
65
|
+
* singleton 单例
|
|
66
|
+
* @param abstract
|
|
67
|
+
* @param concrete
|
|
68
|
+
*/
|
|
69
|
+
singleton(abstract: string, concrete: any): void;
|
|
70
|
+
/**
|
|
71
|
+
* getInstance 获取实例
|
|
72
|
+
*
|
|
73
|
+
*/
|
|
74
|
+
static getInstance<Instance>(): Container | Instance;
|
|
75
|
+
/**
|
|
76
|
+
* proxyInstance 代理实例
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
protected proxyInstance(): this;
|
|
80
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HttpAdapterInterface } from '../Type/adapters';
|
|
2
|
+
/**
|
|
3
|
+
* Class AxiosAdapter
|
|
4
|
+
* @description axios适配器,适配器主要完成
|
|
5
|
+
*/
|
|
6
|
+
export default class AxiosAdapter extends HttpAdapterInterface<{}> {
|
|
7
|
+
/**
|
|
8
|
+
* Method request
|
|
9
|
+
* @returns Promise
|
|
10
|
+
*/
|
|
11
|
+
request(): Promise<unknown>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Service from '../Service/Service';
|
|
2
|
+
import type { IResponseReturn, TResponseDataReturn, IHelper } from '../Type/types';
|
|
3
|
+
/**
|
|
4
|
+
* Class Helper
|
|
5
|
+
* @extends Service
|
|
6
|
+
*/
|
|
7
|
+
export default class Helper extends Service implements IHelper {
|
|
8
|
+
env(): Record<any, any>;
|
|
9
|
+
private webStorage;
|
|
10
|
+
/**
|
|
11
|
+
* Local storage
|
|
12
|
+
* @param name
|
|
13
|
+
* @param payload
|
|
14
|
+
*/
|
|
15
|
+
storage(name?: string, payload?: any): any | Record<any, any>;
|
|
16
|
+
cookie(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Session storage
|
|
19
|
+
* @param name
|
|
20
|
+
* @param payload
|
|
21
|
+
*/
|
|
22
|
+
session(name?: string, payload?: any): any | Record<any, any>;
|
|
23
|
+
/**
|
|
24
|
+
* Method http
|
|
25
|
+
* 发起一个http请求
|
|
26
|
+
* @param api
|
|
27
|
+
* @param data
|
|
28
|
+
* @param handle
|
|
29
|
+
*/
|
|
30
|
+
http(api: any, data: any, handle: any): Promise<TResponseDataReturn | IResponseReturn | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* 发送一个Http请求
|
|
33
|
+
* @param api
|
|
34
|
+
* @param data
|
|
35
|
+
* @param handle
|
|
36
|
+
* @param config
|
|
37
|
+
* @param returnResponse
|
|
38
|
+
*/
|
|
39
|
+
send(api: any, data: any, handle: any, config: any, returnResponse?: boolean): Promise<TResponseDataReturn | IResponseReturn>;
|
|
40
|
+
checkAuth(): void;
|
|
41
|
+
cookies(name: string): Record<any, any>;
|
|
42
|
+
cookies(name: string, payload?: any): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
declare type Type = "localStorage" | "sessionStorage";
|
|
2
|
+
/**
|
|
3
|
+
* Class WebStorage
|
|
4
|
+
* 浏览器存储
|
|
5
|
+
*/
|
|
6
|
+
export default class WebStorage {
|
|
7
|
+
type: Type;
|
|
8
|
+
storage: Storage;
|
|
9
|
+
/**
|
|
10
|
+
* constructor
|
|
11
|
+
* @param {String} type 存储类型
|
|
12
|
+
*/
|
|
13
|
+
constructor({ type }: {
|
|
14
|
+
type: Type;
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* get get|getAll storage
|
|
18
|
+
* @param key
|
|
19
|
+
*/
|
|
20
|
+
get(key?: string): string | any;
|
|
21
|
+
/**
|
|
22
|
+
* set
|
|
23
|
+
* Set storage 保持/设置数据
|
|
24
|
+
* @param key
|
|
25
|
+
* @param value
|
|
26
|
+
*/
|
|
27
|
+
set(key: string, value: string | any[] | Record<any, any>): void;
|
|
28
|
+
/**
|
|
29
|
+
* save
|
|
30
|
+
* Save storage as set set的别名
|
|
31
|
+
* @param key
|
|
32
|
+
* @param value
|
|
33
|
+
*/
|
|
34
|
+
save(key: string, value: string | any[] | Record<any, any>): void;
|
|
35
|
+
/**
|
|
36
|
+
* delete
|
|
37
|
+
* Delete storage 删除一个或数组内多个
|
|
38
|
+
* @param {String|Array<string>} key
|
|
39
|
+
*/
|
|
40
|
+
delete(key: string | string[]): void;
|
|
41
|
+
/**
|
|
42
|
+
* remove
|
|
43
|
+
* Remove storage as delete delete的别名
|
|
44
|
+
* @param key
|
|
45
|
+
*/
|
|
46
|
+
remove(key: string | string[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* clear
|
|
49
|
+
* Clear storage 清空
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* keys
|
|
54
|
+
* Get storage keys 获取全部键
|
|
55
|
+
* @return keys
|
|
56
|
+
*/
|
|
57
|
+
keys(): string[];
|
|
58
|
+
/**
|
|
59
|
+
* getAll
|
|
60
|
+
* Get storage key & val 获取全部键值对
|
|
61
|
+
*/
|
|
62
|
+
getAll(): Record<any, any>;
|
|
63
|
+
/**
|
|
64
|
+
* setConfig
|
|
65
|
+
* @param type
|
|
66
|
+
*/
|
|
67
|
+
setConfig({ type }: {
|
|
68
|
+
type: Type;
|
|
69
|
+
}): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exception Class
|
|
3
|
+
* 目前原生的错误类型
|
|
4
|
+
* Error [一般错误类型]
|
|
5
|
+
* SyntaxError [语法错误]
|
|
6
|
+
* ReferenceError [不存在的变量]
|
|
7
|
+
* RangeError [超出有效范围]
|
|
8
|
+
* TypeError [非预期类型]
|
|
9
|
+
* URIError [URI参数错误]
|
|
10
|
+
* EvalError [eval函数没有正确执行]
|
|
11
|
+
* Example: throw new Exception() catch(error) error.name,error.message,error.code,error.stack
|
|
12
|
+
*/
|
|
13
|
+
export default class Exception extends Error {
|
|
14
|
+
name: string;
|
|
15
|
+
message: string;
|
|
16
|
+
code: number;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {String} name 错误名称
|
|
20
|
+
* @param {String} message 错误提示
|
|
21
|
+
* @param {Number} code 错误码
|
|
22
|
+
*/
|
|
23
|
+
constructor(name: string, message: string, code?: number);
|
|
24
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
declare type variableType = "string" | "number" | "object" | "undefined" | "function" | "boolean" | "bigInt" | "symbol";
|
|
2
|
+
declare type TrimType = "R" | "L" | "";
|
|
3
|
+
/**
|
|
4
|
+
* Class Lib
|
|
5
|
+
* 基础函数库,Lodash、Underscore... So big
|
|
6
|
+
*/
|
|
7
|
+
export default class Lib {
|
|
8
|
+
/**
|
|
9
|
+
* typeOf 判断变量类型
|
|
10
|
+
* @param value
|
|
11
|
+
* @param type
|
|
12
|
+
*/
|
|
13
|
+
static typeOf<T>(value: unknown, type: variableType): value is T;
|
|
14
|
+
/**
|
|
15
|
+
* getTag 判断变量类型
|
|
16
|
+
* @param value
|
|
17
|
+
*/
|
|
18
|
+
static getTag(value: unknown): string;
|
|
19
|
+
/**
|
|
20
|
+
* isFunction 是否函数
|
|
21
|
+
* @param {Function} value
|
|
22
|
+
* @return {Boolean}
|
|
23
|
+
*/
|
|
24
|
+
static isFunction(value: unknown): value is typeof Function;
|
|
25
|
+
/**
|
|
26
|
+
* isString 是否字符串
|
|
27
|
+
* @param {String} value
|
|
28
|
+
* @return {Boolean}
|
|
29
|
+
*/
|
|
30
|
+
static isString(value: unknown): value is string;
|
|
31
|
+
/**
|
|
32
|
+
* isNumber 是否数字
|
|
33
|
+
* @param value
|
|
34
|
+
* @return {Boolean}
|
|
35
|
+
*/
|
|
36
|
+
static isNumber(value: unknown): value is number;
|
|
37
|
+
/**
|
|
38
|
+
* isObject 是否对象
|
|
39
|
+
* @param {Object} value
|
|
40
|
+
*/
|
|
41
|
+
static isObject(value: unknown): value is Record<any, any>;
|
|
42
|
+
/**
|
|
43
|
+
* isObject 是否Undefined
|
|
44
|
+
* @param {*} value
|
|
45
|
+
* @return boolean
|
|
46
|
+
*/
|
|
47
|
+
static isUndefined(value: unknown): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* isNull 是否Null
|
|
50
|
+
* @param value
|
|
51
|
+
*/
|
|
52
|
+
static isNull(value: unknown): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* isEmpty 是否空
|
|
55
|
+
* 目前只对 null undefined '' {} [] 做处理
|
|
56
|
+
* @param value
|
|
57
|
+
*/
|
|
58
|
+
static isEmpty(value: unknown): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* isClass 是否类
|
|
61
|
+
* @param value
|
|
62
|
+
*/
|
|
63
|
+
static isClass(value: unknown): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* 字符串去除首尾字符
|
|
66
|
+
* @param str 字符串
|
|
67
|
+
* @param char 字符
|
|
68
|
+
* @param type 类型
|
|
69
|
+
*/
|
|
70
|
+
static strTrim(str: string, char: string, type?: TrimType): string;
|
|
71
|
+
}
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ServiceProvider from "./ServiceProvider";
|
|
2
|
+
/**
|
|
3
|
+
* @name HttpProvider
|
|
4
|
+
* @description HTTP服务提供者,对HTTP服务进行注册
|
|
5
|
+
*/
|
|
6
|
+
export default class HttpProvider extends ServiceProvider {
|
|
7
|
+
/**
|
|
8
|
+
* Method Register
|
|
9
|
+
* 注册服务
|
|
10
|
+
* @protected
|
|
11
|
+
*/
|
|
12
|
+
register(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IApplicationInstance } from '../Type/types';
|
|
2
|
+
export default abstract class ServiceProvider {
|
|
3
|
+
protected app: import("../Type/types").IApplication;
|
|
4
|
+
/**
|
|
5
|
+
* constructor
|
|
6
|
+
* @param app Application instance
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
constructor(app: IApplicationInstance);
|
|
10
|
+
/**
|
|
11
|
+
* register
|
|
12
|
+
* 注册 provider
|
|
13
|
+
*/
|
|
14
|
+
register(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import Service from "./Service";
|
|
2
|
+
import RESTful from "../Spanner/RESTful";
|
|
3
|
+
import type { TContentType, TCarryData, IHttpSendConfig, RequestMethod, HTTP_SERVICE_CONFIG, DATA_CARRYING } from "../Type/types";
|
|
4
|
+
import type { UtilityObject } from "../Type/utility";
|
|
5
|
+
declare type IApplicationInstance = any;
|
|
6
|
+
/**
|
|
7
|
+
* Class HttpService
|
|
8
|
+
*/
|
|
9
|
+
export default class HttpService extends Service {
|
|
10
|
+
_http: any;
|
|
11
|
+
_api: UtilityObject;
|
|
12
|
+
_headers: UtilityObject;
|
|
13
|
+
_host: string;
|
|
14
|
+
_isRESTful: boolean;
|
|
15
|
+
_RESTful: typeof RESTful;
|
|
16
|
+
_carryingData: UtilityObject;
|
|
17
|
+
_mode: string;
|
|
18
|
+
$helper: null;
|
|
19
|
+
_requestMiddleware: CallableFunction;
|
|
20
|
+
_responseMiddleware: CallableFunction;
|
|
21
|
+
/**
|
|
22
|
+
* _contentType Request type 请求类型
|
|
23
|
+
* 'application/json' 为 Request Payload 请求方式
|
|
24
|
+
* 'application/x-www-form-urlencoded;charset=UTF-8' 为 Form Data 请求方式 需QS配合使用
|
|
25
|
+
* OTHER Query String Parameters 为 _method = 'GET'
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Constructor
|
|
29
|
+
* @param {Object} app
|
|
30
|
+
* @param {Object} HTTP_ADAPTER
|
|
31
|
+
* @param {String} HTTP_API
|
|
32
|
+
* @param {String} HTTP_HOST
|
|
33
|
+
* @param {Boolean} IS_RESTFUL
|
|
34
|
+
* @param {String} CONTENT_TYPE
|
|
35
|
+
* @param {Object} DATA_CARRYING
|
|
36
|
+
* @param {Function} REQUEST_MIDDLEWARE
|
|
37
|
+
* @param {Function} RESPONSE_MIDDLEWARE
|
|
38
|
+
*/
|
|
39
|
+
constructor(app: IApplicationInstance, { HTTP_ADAPTER, HTTP_API, HTTP_HOST, IS_RESTFUL, CONTENT_TYPE, DATA_CARRYING, REQUEST_MIDDLEWARE, RESPONSE_MIDDLEWARE, }: HTTP_SERVICE_CONFIG);
|
|
40
|
+
/**
|
|
41
|
+
* Method setContentType 设置请求类型
|
|
42
|
+
* @param {String} mode
|
|
43
|
+
*/
|
|
44
|
+
setContentType(mode: TContentType): void;
|
|
45
|
+
/**
|
|
46
|
+
* Method setDataCarry 处理携带数据
|
|
47
|
+
* @param {*} REQUEST_HEADERS
|
|
48
|
+
* @param {*} REQUEST_DATA
|
|
49
|
+
*/
|
|
50
|
+
setDataCarry(REQUEST_HEADERS: DATA_CARRYING["REQUEST_HEADERS"], REQUEST_DATA: DATA_CARRYING["REQUEST_DATA"]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Method carryingHandle 携带数据处理
|
|
53
|
+
* @param {String} name
|
|
54
|
+
* @param {*} val
|
|
55
|
+
* @param {*} type
|
|
56
|
+
*/
|
|
57
|
+
carryingHandle(name: string, val: any, type?: TCarryData): void;
|
|
58
|
+
/**
|
|
59
|
+
* Method http 发送一个请求
|
|
60
|
+
* @param {String} apiRoute
|
|
61
|
+
* @param {JSON} data
|
|
62
|
+
* @param {Boolean} returnResponse
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
http(apiRoute: string, data: Record<string, any>, returnResponse?: boolean): Promise<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Send Request
|
|
68
|
+
* @param {Boolean} returnResponse 返回response还是response.data
|
|
69
|
+
* @returns {Promise<*|*>}
|
|
70
|
+
*/
|
|
71
|
+
request(returnResponse: boolean): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Method Send
|
|
74
|
+
* 发送一个自定义请求
|
|
75
|
+
* @param apiRoute
|
|
76
|
+
* @param data
|
|
77
|
+
* @param config
|
|
78
|
+
* @returns {Promise<void>}
|
|
79
|
+
*/
|
|
80
|
+
send(apiRoute: string, data: Record<string, any>, config?: IHttpSendConfig): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Method getParameters
|
|
83
|
+
* 从Api里读取请求方法、参数和地址
|
|
84
|
+
* @param {*} apiRoute
|
|
85
|
+
* @param {*} data
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
getParameters(apiRoute: string, data: Record<string, any>): {
|
|
89
|
+
url: string;
|
|
90
|
+
method: RequestMethod;
|
|
91
|
+
data: any;
|
|
92
|
+
auth: boolean;
|
|
93
|
+
params: {
|
|
94
|
+
host: string;
|
|
95
|
+
method: RequestMethod;
|
|
96
|
+
uri: string;
|
|
97
|
+
data: any;
|
|
98
|
+
auth: boolean;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Method transformRESTful
|
|
103
|
+
* 使用扳手工具处理RESTful数据
|
|
104
|
+
* @param {*} uri
|
|
105
|
+
* @param {*} data
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
transformRESTful(uri: string, data?: Record<string, any>): {
|
|
109
|
+
uri: string;
|
|
110
|
+
data: any;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Method setHeaders
|
|
114
|
+
* 设置Headers multiple
|
|
115
|
+
* @param {JSON|Object} config
|
|
116
|
+
*/
|
|
117
|
+
setHeaders(config?: {}): void;
|
|
118
|
+
/**
|
|
119
|
+
* Method setHeader
|
|
120
|
+
* 设置Headers single
|
|
121
|
+
* @param {String} name
|
|
122
|
+
* @param {String} val
|
|
123
|
+
*/
|
|
124
|
+
setHeader(name: string, val: string | number | any): void;
|
|
125
|
+
/**
|
|
126
|
+
* Method setData
|
|
127
|
+
* 设置携带数据 通过Data
|
|
128
|
+
* @param {*} name
|
|
129
|
+
* @param {*} val
|
|
130
|
+
*/
|
|
131
|
+
setData(name: string, val: string | number | any): void;
|
|
132
|
+
}
|
|
133
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class RESTful
|
|
3
|
+
* RESTful处理类
|
|
4
|
+
* @author SunnyXu <xy@ztes.com>
|
|
5
|
+
*/
|
|
6
|
+
export default class RESTful {
|
|
7
|
+
private readonly isRESTful;
|
|
8
|
+
private uri;
|
|
9
|
+
private readonly requestData;
|
|
10
|
+
/**
|
|
11
|
+
* Method constructor
|
|
12
|
+
* @param {String} uri
|
|
13
|
+
* @param {*} data
|
|
14
|
+
* @param {*} mode
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
constructor(uri: string, data: any, mode: boolean);
|
|
18
|
+
/**
|
|
19
|
+
* Method create
|
|
20
|
+
* 创建RESTful数据
|
|
21
|
+
*/
|
|
22
|
+
create(): {
|
|
23
|
+
uri: string;
|
|
24
|
+
data: any;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* private method transformer
|
|
28
|
+
*/
|
|
29
|
+
private transformer;
|
|
30
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare type Callback = (item: Record<any, any>, index?: number) => Record<any, any>;
|
|
2
|
+
/**
|
|
3
|
+
* Class Transformer 转换器
|
|
4
|
+
* NewTransformer extends Transformer -> constructor(){super(data,payload)}
|
|
5
|
+
*/
|
|
6
|
+
export default class Transformer {
|
|
7
|
+
private readonly data;
|
|
8
|
+
private payload;
|
|
9
|
+
/**
|
|
10
|
+
* Method constructor
|
|
11
|
+
* @param {*} data 需处理的数据
|
|
12
|
+
* @param {*} payload 携带的载荷
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
constructor(data: any, payload?: unknown);
|
|
16
|
+
/**
|
|
17
|
+
* Method transform
|
|
18
|
+
* 转换方法
|
|
19
|
+
* @param {Object|String|Number} data
|
|
20
|
+
* @param tData
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
transform(data: any, tData?: any): any;
|
|
24
|
+
/**
|
|
25
|
+
* Method create
|
|
26
|
+
* 创建新数据
|
|
27
|
+
* @return {Array/Object|String|Number|*}
|
|
28
|
+
*/
|
|
29
|
+
create(callback?: Callback): any;
|
|
30
|
+
/**
|
|
31
|
+
* 格式化数字
|
|
32
|
+
* @param {String|Number} number 待处理数字
|
|
33
|
+
* @param {Number} places 小数点位数 -1为原样保留
|
|
34
|
+
* @param {String} thousand 千位字符串 默认为空
|
|
35
|
+
* @param {String} decimal 小数点替换字符 默认为.
|
|
36
|
+
* @return {String|Number}
|
|
37
|
+
*/
|
|
38
|
+
formatNumber(number: string | number, places?: number | string, thousand?: string, decimal?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* formatDate 日期格式化
|
|
41
|
+
* @param {string|number} timestamp
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
formatDate(timestamp?: number | string | unknown): Record<string, number | string>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IHttpAdapter, RequestConfig, RequestMethod } from './types';
|
|
2
|
+
export declare abstract class HttpAdapterInterface<T> {
|
|
3
|
+
protected http: IHttpAdapter<T>;
|
|
4
|
+
protected method: RequestMethod;
|
|
5
|
+
protected url: string;
|
|
6
|
+
protected data: {};
|
|
7
|
+
protected headers: {};
|
|
8
|
+
/**
|
|
9
|
+
* Method constructor 注入Axios
|
|
10
|
+
* @param {*} $function
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
protected constructor($function: IHttpAdapter<T>);
|
|
14
|
+
/**
|
|
15
|
+
* Method setConfig
|
|
16
|
+
* 设置配置信息
|
|
17
|
+
* @param {method,url,data,headers} param
|
|
18
|
+
*/
|
|
19
|
+
setConfig({ method, url, data, headers }: RequestConfig): void;
|
|
20
|
+
/**
|
|
21
|
+
* Method request
|
|
22
|
+
* @returns Promise
|
|
23
|
+
*/
|
|
24
|
+
request(): Promise<unknown>;
|
|
25
|
+
}
|