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.
Files changed (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/framework/es/core/Application.d.ts +126 -0
  4. package/framework/es/core/Command/Command.d.ts +7 -0
  5. package/framework/es/core/Container/Container.d.ts +80 -0
  6. package/framework/es/core/Contracts/AxiosAdapter.d.ts +12 -0
  7. package/framework/es/core/Helper/Helper.d.ts +43 -0
  8. package/framework/es/core/Helper/Storage/WebStorage.d.ts +71 -0
  9. package/framework/es/core/Libs/Exception.d.ts +24 -0
  10. package/framework/es/core/Libs/Lib.d.ts +72 -0
  11. package/framework/es/core/Provider/CommandProvider.d.ts +4 -0
  12. package/framework/es/core/Provider/HelperProvider.d.ts +4 -0
  13. package/framework/es/core/Provider/HttpProvider.d.ts +13 -0
  14. package/framework/es/core/Provider/ServiceProvider.d.ts +15 -0
  15. package/framework/es/core/Service/HttpService.d.ts +133 -0
  16. package/framework/es/core/Service/Service.d.ts +6 -0
  17. package/framework/es/core/Spanner/RESTful.d.ts +30 -0
  18. package/framework/es/core/Transformer/Transformer.d.ts +46 -0
  19. package/framework/es/core/Type/adapters.d.ts +25 -0
  20. package/framework/es/core/Type/types.d.ts +161 -0
  21. package/framework/es/core/TypeFunc/index.d.ts +6 -0
  22. package/framework/es/core/Wrenches/EventBus.d.ts +56 -0
  23. package/framework/es/core/Wrenches/is.d.ts +19 -0
  24. package/framework/es/ege.js +4 -0
  25. package/framework/es/ege.js.map +1 -0
  26. package/framework/es/index.d.ts +13 -0
  27. package/framework/es/pdd.js +4 -0
  28. package/framework/es/pdd.js.map +1 -0
  29. package/framework/es/src/core/Application.d.ts +127 -0
  30. package/framework/es/src/core/Application.d.ts.map +1 -0
  31. package/framework/es/src/core/Command/Command.d.ts +8 -0
  32. package/framework/es/src/core/Command/Command.d.ts.map +1 -0
  33. package/framework/es/src/core/Container/Container.d.ts +81 -0
  34. package/framework/es/src/core/Container/Container.d.ts.map +1 -0
  35. package/framework/es/src/core/Contracts/AxiosAdapter.d.ts +13 -0
  36. package/framework/es/src/core/Contracts/AxiosAdapter.d.ts.map +1 -0
  37. package/framework/es/src/core/Helper/Helper.d.ts +45 -0
  38. package/framework/es/src/core/Helper/Helper.d.ts.map +1 -0
  39. package/framework/es/src/core/Helper/Storage/WebStorage.d.ts +72 -0
  40. package/framework/es/src/core/Helper/Storage/WebStorage.d.ts.map +1 -0
  41. package/framework/es/src/core/Libs/Exception.d.ts +25 -0
  42. package/framework/es/src/core/Libs/Exception.d.ts.map +1 -0
  43. package/framework/es/src/core/Libs/Lib.d.ts +73 -0
  44. package/framework/es/src/core/Libs/Lib.d.ts.map +1 -0
  45. package/framework/es/src/core/Provider/CommandProvider.d.ts +5 -0
  46. package/framework/es/src/core/Provider/CommandProvider.d.ts.map +1 -0
  47. package/framework/es/src/core/Provider/HelperProvider.d.ts +5 -0
  48. package/framework/es/src/core/Provider/HelperProvider.d.ts.map +1 -0
  49. package/framework/es/src/core/Provider/HttpProvider.d.ts +14 -0
  50. package/framework/es/src/core/Provider/HttpProvider.d.ts.map +1 -0
  51. package/framework/es/src/core/Provider/ServiceProvider.d.ts +16 -0
  52. package/framework/es/src/core/Provider/ServiceProvider.d.ts.map +1 -0
  53. package/framework/es/src/core/Service/HttpService.d.ts +128 -0
  54. package/framework/es/src/core/Service/HttpService.d.ts.map +1 -0
  55. package/framework/es/src/core/Service/Service.d.ts +7 -0
  56. package/framework/es/src/core/Service/Service.d.ts.map +1 -0
  57. package/framework/es/src/core/Spanner/RESTful.d.ts +32 -0
  58. package/framework/es/src/core/Spanner/RESTful.d.ts.map +1 -0
  59. package/framework/es/src/core/Transformer/Transformer.d.ts +47 -0
  60. package/framework/es/src/core/Transformer/Transformer.d.ts.map +1 -0
  61. package/framework/es/src/core/Type/adapters.d.ts +26 -0
  62. package/framework/es/src/core/Type/adapters.d.ts.map +1 -0
  63. package/framework/es/src/core/Type/types.d.ts +186 -0
  64. package/framework/es/src/core/Type/types.d.ts.map +1 -0
  65. package/framework/es/src/core/TypeFunc/index.d.ts +8 -0
  66. package/framework/es/src/core/TypeFunc/index.d.ts.map +1 -0
  67. package/framework/es/src/core/Wrenches/EventBus.d.ts +57 -0
  68. package/framework/es/src/core/Wrenches/EventBus.d.ts.map +1 -0
  69. package/framework/es/src/core/Wrenches/is.d.ts +20 -0
  70. package/framework/es/src/core/Wrenches/is.d.ts.map +1 -0
  71. package/framework/es/src/index.d.ts +14 -0
  72. package/framework/es/src/index.d.ts.map +1 -0
  73. package/framework/es/src/utils.d.ts +17 -0
  74. package/framework/es/src/utils.d.ts.map +1 -0
  75. package/framework/es/utils.d.ts +16 -0
  76. package/framework/umd/core/Application.d.ts +126 -0
  77. package/framework/umd/core/Command/Command.d.ts +7 -0
  78. package/framework/umd/core/Container/Container.d.ts +80 -0
  79. package/framework/umd/core/Contracts/AxiosAdapter.d.ts +12 -0
  80. package/framework/umd/core/Helper/Helper.d.ts +43 -0
  81. package/framework/umd/core/Helper/Storage/WebStorage.d.ts +71 -0
  82. package/framework/umd/core/Libs/Exception.d.ts +24 -0
  83. package/framework/umd/core/Libs/Lib.d.ts +72 -0
  84. package/framework/umd/core/Provider/CommandProvider.d.ts +4 -0
  85. package/framework/umd/core/Provider/HelperProvider.d.ts +4 -0
  86. package/framework/umd/core/Provider/HttpProvider.d.ts +13 -0
  87. package/framework/umd/core/Provider/ServiceProvider.d.ts +15 -0
  88. package/framework/umd/core/Service/HttpService.d.ts +133 -0
  89. package/framework/umd/core/Service/Service.d.ts +6 -0
  90. package/framework/umd/core/Spanner/RESTful.d.ts +30 -0
  91. package/framework/umd/core/Transformer/Transformer.d.ts +46 -0
  92. package/framework/umd/core/Type/adapters.d.ts +25 -0
  93. package/framework/umd/core/Type/types.d.ts +161 -0
  94. package/framework/umd/core/TypeFunc/index.d.ts +6 -0
  95. package/framework/umd/core/Wrenches/EventBus.d.ts +56 -0
  96. package/framework/umd/core/Wrenches/is.d.ts +19 -0
  97. package/framework/umd/ege.js +4 -0
  98. package/framework/umd/ege.js.map +1 -0
  99. package/framework/umd/index.d.ts +13 -0
  100. package/framework/umd/pdd.js +4 -0
  101. package/framework/umd/pdd.js.map +1 -0
  102. package/framework/umd/src/core/Application.d.ts +127 -0
  103. package/framework/umd/src/core/Application.d.ts.map +1 -0
  104. package/framework/umd/src/core/Command/Command.d.ts +8 -0
  105. package/framework/umd/src/core/Command/Command.d.ts.map +1 -0
  106. package/framework/umd/src/core/Container/Container.d.ts +81 -0
  107. package/framework/umd/src/core/Container/Container.d.ts.map +1 -0
  108. package/framework/umd/src/core/Contracts/AxiosAdapter.d.ts +13 -0
  109. package/framework/umd/src/core/Contracts/AxiosAdapter.d.ts.map +1 -0
  110. package/framework/umd/src/core/Helper/Helper.d.ts +45 -0
  111. package/framework/umd/src/core/Helper/Helper.d.ts.map +1 -0
  112. package/framework/umd/src/core/Helper/Storage/WebStorage.d.ts +72 -0
  113. package/framework/umd/src/core/Helper/Storage/WebStorage.d.ts.map +1 -0
  114. package/framework/umd/src/core/Libs/Exception.d.ts +25 -0
  115. package/framework/umd/src/core/Libs/Exception.d.ts.map +1 -0
  116. package/framework/umd/src/core/Libs/Lib.d.ts +73 -0
  117. package/framework/umd/src/core/Libs/Lib.d.ts.map +1 -0
  118. package/framework/umd/src/core/Provider/CommandProvider.d.ts +5 -0
  119. package/framework/umd/src/core/Provider/CommandProvider.d.ts.map +1 -0
  120. package/framework/umd/src/core/Provider/HelperProvider.d.ts +5 -0
  121. package/framework/umd/src/core/Provider/HelperProvider.d.ts.map +1 -0
  122. package/framework/umd/src/core/Provider/HttpProvider.d.ts +14 -0
  123. package/framework/umd/src/core/Provider/HttpProvider.d.ts.map +1 -0
  124. package/framework/umd/src/core/Provider/ServiceProvider.d.ts +16 -0
  125. package/framework/umd/src/core/Provider/ServiceProvider.d.ts.map +1 -0
  126. package/framework/umd/src/core/Service/HttpService.d.ts +128 -0
  127. package/framework/umd/src/core/Service/HttpService.d.ts.map +1 -0
  128. package/framework/umd/src/core/Service/Service.d.ts +7 -0
  129. package/framework/umd/src/core/Service/Service.d.ts.map +1 -0
  130. package/framework/umd/src/core/Spanner/RESTful.d.ts +32 -0
  131. package/framework/umd/src/core/Spanner/RESTful.d.ts.map +1 -0
  132. package/framework/umd/src/core/Transformer/Transformer.d.ts +47 -0
  133. package/framework/umd/src/core/Transformer/Transformer.d.ts.map +1 -0
  134. package/framework/umd/src/core/Type/adapters.d.ts +26 -0
  135. package/framework/umd/src/core/Type/adapters.d.ts.map +1 -0
  136. package/framework/umd/src/core/Type/types.d.ts +186 -0
  137. package/framework/umd/src/core/Type/types.d.ts.map +1 -0
  138. package/framework/umd/src/core/TypeFunc/index.d.ts +8 -0
  139. package/framework/umd/src/core/TypeFunc/index.d.ts.map +1 -0
  140. package/framework/umd/src/core/Wrenches/EventBus.d.ts +57 -0
  141. package/framework/umd/src/core/Wrenches/EventBus.d.ts.map +1 -0
  142. package/framework/umd/src/core/Wrenches/is.d.ts +20 -0
  143. package/framework/umd/src/core/Wrenches/is.d.ts.map +1 -0
  144. package/framework/umd/src/index.d.ts +14 -0
  145. package/framework/umd/src/index.d.ts.map +1 -0
  146. package/framework/umd/src/utils.d.ts +17 -0
  147. package/framework/umd/src/utils.d.ts.map +1 -0
  148. package/framework/umd/utils.d.ts +16 -0
  149. package/index.d.ts +724 -0
  150. package/package.json +57 -0
@@ -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,6 @@
1
+ declare type IApplicationInstance = any;
2
+ export default abstract class Service {
3
+ protected app: IApplicationInstance;
4
+ constructor(app: IApplicationInstance);
5
+ }
6
+ 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
+ }
@@ -0,0 +1,161 @@
1
+ import type { UtilityFunction, UtilityObject, UtilityClass } from './utility';
2
+ import type ServiceProvider from '../Provider/ServiceProvider';
3
+ /**
4
+ * Interface Container
5
+ * @description 容器接口
6
+ */
7
+ export interface IContainer {
8
+ /**
9
+ * bind 绑定实体
10
+ * @param {String|Array} abstract
11
+ * @param {*} concrete
12
+ */
13
+ bind(abstract: string | string[], concrete: any): void;
14
+ /**
15
+ * make 创建类的实例/获取对象 create instance/object
16
+ * @param abstract
17
+ * @param params
18
+ * @param shared
19
+ */
20
+ make(abstract: string, params?: object | [], shared?: boolean): any;
21
+ /**
22
+ * has as existence
23
+ * 是否存在标识 existence 的别名
24
+ * @param {String} name
25
+ */
26
+ has(name: string): boolean;
27
+ /**
28
+ * existence 存在标识
29
+ * @param {String} name
30
+ */
31
+ existence(name: string): boolean;
32
+ /**
33
+ * getAlias 获取别名
34
+ * @param abstract
35
+ */
36
+ getAlias(abstract: string): string;
37
+ /**
38
+ * get 获取实例
39
+ * @param abstract
40
+ */
41
+ get(abstract: string): any;
42
+ /**
43
+ * singleton 单例
44
+ * @param abstract
45
+ * @param concrete
46
+ */
47
+ singleton(abstract: string, concrete: any): void;
48
+ }
49
+ /**
50
+ * Interface Application
51
+ * @description 应用接口
52
+ */
53
+ export interface IApplication extends IContainer {
54
+ /**
55
+ * getterProviders Providers 获取器
56
+ */
57
+ getterProviders(): any[];
58
+ /**
59
+ * setterProviders Providers
60
+ * 设置器
61
+ * @param providers
62
+ */
63
+ setterProviders<T>(providers: T[]): void;
64
+ /**
65
+ * static getAdapter
66
+ * 适配器 获取器
67
+ * @param adapter
68
+ */
69
+ getterAdapter(adapter: UtilityClass): any;
70
+ /**
71
+ * setAdapter
72
+ * 新增
73
+ * @param adapter
74
+ * @param instance
75
+ * @protected
76
+ */
77
+ setterAdapter(adapter: UtilityClass, instance: UtilityObject): void;
78
+ }
79
+ export declare type IApplicationInstance = IApplication;
80
+ export declare type RequestMethod = 'post' | 'get' | 'put' | 'delete' | 'POST' | 'GET' | 'PUT' | 'DELETE';
81
+ export declare type TContentType = 'REQUEST_PAYLOAD' | 'FORM_DATA';
82
+ export declare type TCarryData = 'REQUEST_HEADERS' | 'REQUEST_DATA';
83
+ export declare type TApiRoute = [string, RequestMethod?, boolean?];
84
+ export interface HttpApis {
85
+ [api: string]: TApiRoute;
86
+ }
87
+ export declare type IHttpSendConfig = {
88
+ host?: string;
89
+ headers?: Record<string, any>;
90
+ mode?: TContentType;
91
+ responseData?: boolean;
92
+ };
93
+ export declare type TResponseDataReturn = {
94
+ statusCode: number;
95
+ msg: string;
96
+ data: any;
97
+ timestamp: number;
98
+ };
99
+ export interface IResponseReturn extends Response {
100
+ data: TResponseDataReturn;
101
+ }
102
+ export interface IHelper {
103
+ env(): Record<any, any>;
104
+ storage(name: string): Record<any, any>;
105
+ storage(name: string, payload?: any): void;
106
+ cookies(name: string): Record<any, any>;
107
+ cookies(name: string, payload?: any): void;
108
+ session(name: string): Record<any, any>;
109
+ session(name: string, payload?: any): void;
110
+ /**
111
+ * 发送一个http请求
112
+ * @param api 接口key
113
+ * @param data 请求数据
114
+ * @param handle 处理Response的函数
115
+ */
116
+ http(api: string, data?: UtilityObject, handle?: (response: IResponseReturn) => void): Promise<TResponseDataReturn>;
117
+ send(api: string, data?: UtilityObject, handle?: (response: IResponseReturn) => void, config?: IHttpSendConfig, returnResponse?: boolean): Promise<IResponseReturn>;
118
+ }
119
+ /**
120
+ * Adapter Interface
121
+ */
122
+ export declare type RequestConfig = {
123
+ method?: RequestMethod;
124
+ url?: string;
125
+ data?: Record<string, any>;
126
+ headers?: HeadersInit | Record<string, string | number>;
127
+ };
128
+ export declare type IHttpAdapter<T> = (config: RequestConfig) => Promise<T>;
129
+ export declare type IAxiosAdapterHttp<T> = (config: RequestConfig) => Promise<T>;
130
+ /**
131
+ * Service Interface
132
+ */
133
+ export interface IHttpService {
134
+ send(apiRoute: string, data: Record<string, any>, config?: IHttpSendConfig, returnResponse?: boolean): Promise<any>;
135
+ }
136
+ export declare type IServiceProvider = typeof ServiceProvider;
137
+ export declare type APP_CONFIG = {
138
+ PROVIDERS?: IServiceProvider[];
139
+ APP_TYPE: 'VUE' | 'REACT' | 'UNI_APP' | 'MP_VUE' | 'WX_APP';
140
+ HTTP_CONFIG: HTTP_CONFIG;
141
+ };
142
+ export declare type HTTP_CONFIG = {
143
+ HTTP_ADAPTER: any;
144
+ HTTP_LIB: UtilityFunction | UtilityClass;
145
+ HTTP_API: any;
146
+ HTTP_HOST: string;
147
+ IS_RESTFUL: boolean;
148
+ CONTENT_TYPE: TContentType;
149
+ DATA_CARRYING: DATA_CARRYING;
150
+ REQUEST_MIDDLEWARE?: HttpMiddleware<any>;
151
+ RESPONSE_MIDDLEWARE?: HttpMiddleware<any>;
152
+ };
153
+ export declare type DATA_CARRYING = {
154
+ REQUEST_DATA?: Record<any, any>;
155
+ REQUEST_HEADERS?: Record<any, any>;
156
+ };
157
+ export declare type HttpMiddleware<T> = (http: T | any) => void;
158
+ export declare type HTTP_SERVICE_CONFIG = Pick<HTTP_CONFIG, 'HTTP_ADAPTER' | 'HTTP_API' | 'HTTP_HOST' | 'IS_RESTFUL' | 'CONTENT_TYPE' | 'DATA_CARRYING' | 'REQUEST_MIDDLEWARE' | 'RESPONSE_MIDDLEWARE'>;
159
+ export interface IMiddleware<TContext> {
160
+ handle(context: TContext, next: UtilityFunction): void;
161
+ }
@@ -0,0 +1,6 @@
1
+ import type { APP_CONFIG, HTTP_CONFIG } from '../Type/types';
2
+ import { HttpApis } from '../Type/types';
3
+ export declare function defineAppConfig(config: APP_CONFIG): APP_CONFIG;
4
+ export declare function defineAppHttpConfig<T>(config: HTTP_CONFIG | T): T | HTTP_CONFIG;
5
+ export declare function defineHttpConfig<T>(config: HTTP_CONFIG | T): HTTP_CONFIG | T;
6
+ export declare function defineHttpApis(apis: HttpApis): HttpApis;
@@ -0,0 +1,56 @@
1
+ export declare type Function = (...args: any[]) => any;
2
+ export default class EventBus {
3
+ _events: Map<any, any>;
4
+ static _instance: InstanceType<typeof EventBus>;
5
+ /**
6
+ * 获取EventBus实例
7
+ * @return {EventBus}
8
+ */
9
+ static getInstance(): EventBus;
10
+ /**
11
+ * EventBus.getEvents
12
+ * @return {Map<any, any>}
13
+ */
14
+ static getEvents(): Map<any, any>;
15
+ static getEventsSize(): number;
16
+ static getEvent(name: string): any;
17
+ static hasEvent(name: string): boolean;
18
+ static deleteEvent(name: string): boolean;
19
+ /**
20
+ * Method EventBus.setEvent
21
+ * @param name
22
+ * @param callback
23
+ * @return {Map<any, any>}
24
+ */
25
+ static setEvent(name: string, callback: CallableFunction): Map<any, any>;
26
+ /**
27
+ * Method EventBus.on as EventBus.setEvent
28
+ * 绑定事件
29
+ * @param name
30
+ * @param callback
31
+ * @return {Map<*, *>}
32
+ */
33
+ static on(name: string, callback: CallableFunction): Map<any, any>;
34
+ /**
35
+ * Method EventBus.emit
36
+ * 执行事件
37
+ * @param name
38
+ * @param payload
39
+ * @return {*}
40
+ */
41
+ static emit(name: string, ...payload: any[]): any;
42
+ /**
43
+ * Method EventBus.once
44
+ * 执行事件并关闭事件
45
+ * @param name
46
+ * @param payload
47
+ */
48
+ static once(name: string, ...payload: any[]): void;
49
+ /**
50
+ * EventBus.off
51
+ * 关闭事件
52
+ * @param name
53
+ * @return {boolean}
54
+ */
55
+ static off(name: string): boolean;
56
+ }
@@ -0,0 +1,19 @@
1
+ export declare function isArray(obj: any): obj is any[];
2
+ export declare function isNull(obj: any): obj is null;
3
+ export declare function isBoolean(obj: unknown): obj is boolean;
4
+ export declare function isObject(obj: any): obj is Record<string, unknown>;
5
+ export declare const isPromise: <T>(obj: unknown) => obj is Promise<T>;
6
+ export declare function isString(obj: any): obj is string;
7
+ export declare function isNumber(obj: any): obj is number;
8
+ export declare function isRegExp(obj: any): boolean;
9
+ export declare function isDate(obj: any): boolean;
10
+ export declare function isColor(color: any): boolean;
11
+ export declare function isUndefined(obj: any): obj is undefined;
12
+ export declare function isFunction(obj: any): obj is (...args: any[]) => any;
13
+ export declare function isClass(value: unknown): boolean;
14
+ export declare function isEmptyObject(obj: any): boolean;
15
+ export declare function isEmpty(obj: any): boolean;
16
+ export declare function isExist(obj: any): boolean;
17
+ export declare function isWindow(el: any): el is Window;
18
+ export declare function isPhone(obj: any): boolean;
19
+ export declare function isEmail(obj: any): boolean;
@@ -0,0 +1,4 @@
1
+ import qs from"qs";class Exception extends Error{name="Error";message="Error message";code=500;constructor(t,e,s=500){super(e),this.name=t??"Error",this.message=e??"Error message",this.code=s??500}}class Lib{static typeOf(t,e){return typeof t===e}static getTag(t){return Object.prototype.toString.call(t)}static isFunction(t){return Lib.typeOf(t,"function")&&"[object Function]"===Lib.getTag(t)}static isString(t){return Lib.typeOf(t,"string")||"[object String]"===Lib.getTag(t)}static isNumber(t){return"number"==typeof t}static isObject(t){return"[object Object]"===Lib.getTag(t)}static isUndefined(t){return void 0===t||"[object Undefined]"===Lib.getTag(t)}static isNull(t){return null===t||"[object Null]"===Lib.getTag(t)}static isEmpty(t){return!t&&0!==t||!(!Lib.isObject(t)&&!Array.isArray(t))&&("{}"===JSON.stringify(t)||"[]"===JSON.stringify(t))}static isClass(t){if(Lib.isFunction(t)){const e=t.toString();if(void 0!==t.prototype&&t.prototype.constructor===t){if("class "===e.slice(0,6))return!0;if(2<=Object.getOwnPropertyNames(t.prototype).length)return!0;/^function\s+\(|^function\s+anonymous\(/.test(e)}}return!1}static strTrim(t,e,s){return e?"L"===s?t.replace(new RegExp("^\\"+e+"+","g"),""):"R"===s?t.replace(new RegExp("\\"+e+"+$","g"),""):t.replace(new RegExp("^\\"+e+"+|\\"+e+"+$","g"),""):t.replace(/^\s+|\s+$/g,"")}}class Container{static instance;instances=new Map;bindings={};aliases={};bind(t,e){if(!t)throw new Exception("Abstract Error","Abstract not null");if(Array.isArray(t))t.map(t=>{this.bind(t,e)});else{if(!Lib.isString(t))throw new Exception("Abstract Error","The abstract name is a string");Lib.isObject(e)||Lib.isClass(e)?this.bindings[t]=e:Lib.isFunction(e)&&!Lib.isClass(e)&&this.instances.set(t,e)}}make(t,e,s=!1){var i;if(t=this.getAlias(t),this.has(t))return i=this.instances.get(t)||this.bindings[t],Lib.isClass(i)?this.makeClass(t,i,e,s):Lib.isFunction(i)?this.makeFunc(t,i,e,s):i;throw new Exception("Container Error","The abstract does not exist")}makeClass(t,e,s,i=!1){var r=()=>new e(s);return i?(this.bind(t,r),this.instances.get(t)):r}makeFunc(t,e,s,i=!1){e=e(s);return i?(this.bind(t,e),this.instances.get(t)):e}has(t){return this.existence(t)}existence(t){return!this.bindings[t]||!this.instances.get(t)||!this.getAlias(t)}getAlias(t){return this.aliases[t]||t}get(t){if(this.has(t))return this.make(t);throw new Exception("Container Error","The abstract does not exist")}singleton(t,e){this.bind(t,e)}static getInstance(){let t=this.instance;return t=t&&t instanceof Container?t:this.instance=new Container}proxyInstance(){return new Proxy(this,{get:(t,e)=>t[e]})}}const opt=Object.prototype.toString;function isArray(t){return"[object Array]"===opt.call(t)}function isNull(t){return"[object Null]"===opt.call(t)}function isBoolean(t){return"[object Boolean]"===opt.call(t)}function isObject(t){return"[object Object]"===opt.call(t)}const isPromise=t=>"[object Promise]"===opt.call(t);function isString(t){return"[object String]"===opt.call(t)}function isNumber(t){return"[object Number]"===opt.call(t)&&t==t}function isRegExp(t){return"[object RegExp]"===opt.call(t)}function isDate(t){return"[object Date]"===opt.call(t)}function isHex(t){return/^#[a-fA-F0-9]{3}$|#[a-fA-F0-9]{6}$/.test(t)}function isRgb(t){return/^rgb\((\s*\d+\s*,?){3}\)$/.test(t)}function isRgba(t){return/^rgba\((\s*\d+\s*,\s*){3}\s*\d(\.\d+)?\s*\)$/.test(t)}function isColor(t){return isHex(t)||isRgb(t)||isRgba(t)}function isUndefined(t){return void 0===t}function isFunction(t){return"function"==typeof t}function isClass(t){if("function"==typeof t){const e=t.toString();if(void 0!==t.prototype&&t.prototype.constructor===t){if("class "===e.slice(0,6))return!0;if(2<=Object.getOwnPropertyNames(t.prototype).length)return!0;/^function\s+\(|^function\s+anonymous\(/.test(e)}}return!1}function isEmptyObject(t){return isObject(t)&&0===Object.keys(t).length}function isEmpty(t){return!t&&0!==t||isEmptyObject(t)}function isExist(t){return t||0===t}function isWindow(t){return t===window}function isPhone(t){return/^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]{8}$/.test(t)}function isEmail(t){return/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(t)}var is=Object.freeze({__proto__:null,isArray:isArray,isNull:isNull,isBoolean:isBoolean,isObject:isObject,isPromise:isPromise,isString:isString,isNumber:isNumber,isRegExp:isRegExp,isDate:isDate,isColor:isColor,isUndefined:isUndefined,isFunction:isFunction,isClass:isClass,isEmptyObject:isEmptyObject,isEmpty:isEmpty,isExist:isExist,isWindow:isWindow,isPhone:isPhone,isEmail:isEmail});const Package={version:"localhost"};class Application extends Container{static VERSION=Package.version;adapters=new WeakMap;providers=[];static lifecycle(){const t=(new Date).getTime();return{created:()=>{Application.registerProviders(Application.getProviders()),Application.registerProviders(Application.getConfig("APP_CONFIG").PROVIDERS)},mounted:()=>{},unmounted:()=>{console.log(`
2
+ %c pdd %c ${Application.VERSION} ${(new Date).getTime()-t}ms
3
+ `,"color: #fadfa3; background: #030307; padding:5px 0;border-radius:3px 0 0 3px;","color:#000000;background: #ebd29a; padding:5px 0;border-radius:0 3px 3px 0;")}}}getterProviders(){var t=this.providers;return Array.isArray(t)&&0<t.length?t:[]}static getProviders(){return Application.getInstance().getterProviders()}setterProviders(t){const e=this.providers;Array.isArray(e)&&(this.providers=e.filter(e=>{return!t.find(t=>e===t)}),this.providers=this.getterProviders().concat(t))}static setProviders(t){Application.getInstance().setterProviders(t)}static registerProvider(t){if(!isClass(t))throw new Exception("Provider Error","The first argument must be a class");new t(Application.getInstance()).register()}static registerProviders(t){Array.isArray(t)&&t.map(t=>{Application.registerProvider(t)})}static setConfig(t,e){Application.getInstance().singleton(t,e)}static getConfig(t,e){if(Application.getInstance().has(t))return Application.getInstance().get(t);if(isEmpty(e))throw new Exception("Application Config Error","Configuration information does not exist");return e}static setAppConfig(t){Application.setConfig("APP_CONFIG",t)}static getAppConfig(t){return Application.getConfig("APP_CONFIG",{})[t]}static bindAdapter(t,e){if(!isClass(t))throw new Exception("Adapter Error","The first argument must be a class");e=isEmpty(e)?new t:new t(e);Application.getInstance().setterAdapter(t,e)}setterAdapter(t,e){if(!isClass(t))throw new Exception("Adapter Error","The first argument must be a class");Application.getAdapter(t)&&console.warn("Adapter Warn",`The adapter ${t.name||""} is already bound`),this.adapters.set(t,e)}static getAdapter(t){if(isClass(t))return Application.getInstance().getterAdapter(t);throw new Exception("Adapter Error","The argument must be a class")}getterAdapter(t){return this.adapters.get(t)}static getService(t){return Application.getInstance().get(t)}static getInstance(){let t=Application.instance;return t=t&&t instanceof Application?t:Application.instance=new Application}static run(t){const e=Application.lifecycle();e.created(),e.mounted(),e.unmounted(),isFunction(t)&&t()}}class Command{payload;$helper;constructor(...t){this.payload=[...t],this.$helper=Application.getService("$helper")}}class Transformer{data;payload;constructor(t,e){this.data=t,this.payload=e}transform(t,e){return t}create(s){return Array.isArray(this.data)?this.data.map((t,e)=>Lib.isFunction(s)?s(t,e):this.transform(t)):Lib.isFunction(s)?s(this.data,0):this.transform(this.data)}formatNumber(t,e=-1,s="",i="."){"number"!=typeof t&&(t=Lib.typeOf(t,"string")?parseFloat(t):0);var r=(t=isNaN(t)?0:t).toString().split("."),r=(e=parseInt(e),e=isNaN(Math.abs(e))||-1===e?-1:Math.abs(e),r[1]&&-1===e?e=r[1].length:r[1]||-1!==e||(e=0),s="string"==typeof s?s:",",i=i||".",t<0?"-":"");let n,a;return n=parseInt(t=Math.abs(+t||0).toFixed(e),10).toString(),r+((a=3<(a=n.length)?a%3:0)?n.substr(0,a)+s:"")+n.substr(a).replace(/(\d{3})(?=\d)/g,"$1"+s)+(e?i+Math.abs(Number(t)-Number(n)).toFixed(e).slice(2):"")}formatDate(t=Date.now()){if(Lib.typeOf(t,"string"))return isNaN(Date.parse(t))?this.formatDate():this.formatDate(Date.parse(t));const e=new Date(t),s=e.getFullYear(),i=e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,r=e.getDate()<10?"0"+e.getDate():e.getDate(),n=e.getHours()<10?"0"+e.getHours():e.getHours(),a=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes(),o=e.getSeconds()<10?"0"+e.getSeconds():e.getSeconds();var t=e.getDay(),c=0<=e.getHours()&&n<12?"AM":"PM",p=0<=e.getHours()&&n<12?"上午":"下午";return{Y:s.toString(),M:i.toString(),D:r.toString(),h:n.toString(),m:a.toString(),s:o.toString(),week:["日","一","二","三","四","五","六"][t],ap:c,apCn:p}}}class HttpAdapterInterface{http;method="POST";url="";data={};headers={};constructor(t){if("function"!=typeof t)throw new Exception("HTTP Adapter Error","The first argument must be a function");this.http=t}setConfig({method:t,url:e,data:s,headers:i}){this.method=t??this.method,this.url=e??this.url,this.data=s??this.data,this.headers=i??this.headers}request(){return new Promise((e,s)=>{this.http({method:this.method,url:this.url,data:this.data,headers:this.headers}).then(t=>{e(t)}).catch(t=>{s(t)})})}}class AxiosAdapter extends HttpAdapterInterface{request(){return new Promise((e,s)=>{this.http({method:this.method,url:this.url,data:this.data,headers:this.headers}).then(t=>{e(t)}).catch(t=>{s(t)})})}}class ServiceProvider{app;constructor(t){this.app=t,this.register()}register(){console.log("Service is already registered")}}class CommandProvider extends ServiceProvider{register(){this.app.singleton("$command",()=>{console.log("COMMAND_REGISTERED")})}}class WebStorage{type="localStorage";storage="localStorage"===this.type?localStorage:sessionStorage;constructor({type:t}){this.setConfig({type:t})}get(t){if(!t)return this.getAll();if(Lib.isString(t))return this.storage.getItem(t);throw new Exception("","The first parameter is a string")}set(t,e){if("length"===t)throw new Exception("WebStorage Error","The key of data must not be length");this.storage.setItem(t,JSON.stringify(e))}save(t,e){this.set(t,e)}delete(t){t?Array.isArray(t)?t.map(t=>{this.delete(t)}):this.storage.removeItem(t):this.clear()}remove(t){this.delete(t)}clear(){this.storage.clear()}keys(){var t=this.getAll();return Object.keys(t)}getAll(){const{length:t,...e}=this.storage;return e}setConfig({type:t}){this.type=t}}class Service{app;constructor(t){this.app=t}}class Helper extends Service{env(){return{}}webStorage(t,e,s){const i=new WebStorage({type:t});if(e&&!Lib.isString(e))throw new Exception("WebStorage Error","The first argument must be a string");return void 0!==e||Lib.isString(e)?void 0===s?i.get(e):void i.save(e,s):i.getAll()}storage(t,e){return this.webStorage("localStorage",t,e)}cookie(){}session(t,e){return this.webStorage("sessionStorage",t,e)}async http(t,e,s){try{return await this.send(t,e,s,{},!1)}catch(t){new Exception("HttpError","")}}async send(t,e,s,i,r=!0){if(!this.app.has("$request"))throw new Exception("RequestService Error","");let n=await Application.getService("$request").send(t,e,i);return Lib.isFunction(s)&&(n=s(n)),r?n:n.data}checkAuth(){}cookies(t,e){}}class HelperProvider extends ServiceProvider{register(){this.app.singleton("$helper",()=>new Helper(this.app))}}class RESTful{isRESTful=!0;uri;requestData;constructor(t,e,s){this.isRESTful=s??this.isRESTful,this.uri=t,this.requestData=e}create(){return this.isRESTful?this.transformer():{uri:this.uri,data:this.requestData}}transformer(){let t=Object.keys(this.requestData),i={},r={},e=(t.map(t=>{var e=t.match(/^__/g),s=t.replace(/^__/g,"");e?i[s]=this.requestData[t]:r[s]=this.requestData[t]}),this.uri.match(/<(.*?)>/g)),s={};if(e&&Array.isArray(e)){let t=e.map(t=>{let e=t.replace(/(^<)|(>$)/g,"");t=e.split("=");return 2===t.length?(s[t[0]]=t[1],t[0]):(s[e]=null,e)});return Object.assign(s,i),this.uri=this.uri.replace(/=(.*?)>/g,">"),t.map(t=>{this.uri=this.uri.replace(`<${t}>`,s[t])}),{uri:this.uri,data:r}}return{uri:this.uri,data:this.requestData}}}class HttpService extends Service{_http=null;_api={};_headers={};_host="";_isRESTful=!0;_RESTful;_carryingData={};_mode="REQUEST_PAYLOAD";$helper=null;_requestMiddleware;_responseMiddleware;constructor(t,{HTTP_ADAPTER:e,HTTP_API:s,HTTP_HOST:i,IS_RESTFUL:r,CONTENT_TYPE:n,DATA_CARRYING:a,REQUEST_MIDDLEWARE:o,RESPONSE_MIDDLEWARE:c}){super(t),this._http=e??this._http,this._api=s??this._api,this._host=i??this._host,this._isRESTful=r??!0,this._RESTful=RESTful??null,this.setContentType(n),this.setDataCarry(a.REQUEST_HEADERS,a.REQUEST_DATA),this._requestMiddleware=isFunction(o)?o:t=>t,this._responseMiddleware=isFunction(c)?c:t=>t}setContentType(t){"REQUEST_PAYLOAD"===t?(this._mode=t,this.setHeader("Content-Type","application/json")):"FORM_DATA"===t&&(this._mode=t,this.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"))}setDataCarry(e,s){if(e){const t=Object.keys(e);Array.isArray(t)&&t.map(t=>{this.carryingHandle(t,e[t],"REQUEST_HEADERS")})}if(s){const i=Object.keys(s);Array.isArray(i)&&i.map(t=>{this.carryingHandle(t,s[t],"REQUEST_DATA")})}}carryingHandle(e,s,i="REQUEST_HEADERS"){if(e&&s)if(isFunction(s))try{"REQUEST_HEADERS"===i?this.setHeader(e,s()):"REQUEST_DATA"===i&&this.setData(e,s())}catch(t){console.warn("Application Error",t)}else{let t=null;"LOCAL"===s?t=Application.getService("$helper").storage(e):"SESSION"===s?t=Application.getService("$helper").session(e):"COOKIES"===s?t=Application.getService("$helper").cookies(e):"STORAGE"===s&&(t=Application.getService("$helper").storage(e)),"REQUEST_HEADERS"===i?this.setHeader(e,t):"REQUEST_DATA"===i&&this.setData(e,t)}}async http(t,e,s=!1){try{var i={...this.getParameters(t,e),headers:this._headers},i=this._requestMiddleware(i);this._http.setConfig(i)}catch(t){console.warn("Request config warn",t)}try{return await this.request(s)}catch(t){console.warn("Request interceptor warn",t)}}async request(t){try{var e=await this._http.request();try{var s=this._responseMiddleware(e);return t?s:s.data}catch(t){console.warn("Response middleware Error",t)}return t?e:e.data}catch(t){if(t&&t.response)switch(t.response.status){case 400:t.message="请求参数错误";break;case 401:t.message="未授权,请登录";break;case 403:t.message="跨域拒绝访问";break;case 404:t.message="请求地址出错: "+t.response.config.url;break;case 408:t.message="请求超时";break;case 500:t.message="服务器内部错误";break;case 501:t.message="服务未实现";break;case 502:t.message="网关错误";break;case 503:t.message="服务不可用";break;case 504:t.message="网关超时";break;case 505:t.message="HTTP版本不受支持"}throw this._responseMiddleware({...t.response,message:t.message}),t}}async send(t,e,s={}){return s.host&&(this._host=s.host),s.headers&&this.setHeaders(s.headers),s.mode&&this.setContentType(s.mode),this.http(t,e,!0)}getParameters(t,e){let s=this._api[t];if(!s&&!t)throw new Exception("The api route does not exist","ApiRouteError");let i="",r="POST",n=!0;switch((s=!s&&t?[t]:s).length){case 1:i=s[0];break;case 2:i=s[0],r=s[1];break;case 3:i=s[0],r=s[1],n=s[2];break;default:throw new Exception("ApiRoute Error","The api route does not exist")}r=r.toUpperCase();t={...this._carryingData,...e};const a=this.transformRESTful(i,t);let o=Lib.strTrim(this._host,"/")+"/"+Lib.strTrim(a.uri,"/");return"FORM_DATA"===this._mode&&(a.data=qs.stringify(a.data)),"GET"===r&&(isObject(a.data)&&"REQUEST_PAYLOAD"===this._mode?o=o+"?"+qs.stringify(a.data):a.data&&"FORM_DATA"===this._mode&&(o=o+"?"+a.data)),{url:o,method:r,data:a.data,auth:n,params:{host:this._host.trim(),method:r,uri:a.uri.trim(),data:a.data,auth:n}}}transformRESTful(t,e={}){return new this._RESTful(t,e,this._isRESTful).create()}setHeaders(t={}){this._headers=t}setHeader(t,e){this._headers[t]=e}setData(t,e){this._carryingData[t]=e}}class HttpProvider extends ServiceProvider{register(){var t=Application.getAppConfig("HTTP_CONFIG").HTTP_ADAPTER,e=Application.getAppConfig("HTTP_CONFIG").HTTP_LIB;const s=Application.getAppConfig("HTTP_CONFIG").HTTP_API,i=Application.getAppConfig("HTTP_CONFIG").HTTP_HOST,r=Application.getAppConfig("HTTP_CONFIG").IS_RESTFUL,n=Application.getAppConfig("HTTP_CONFIG").CONTENT_TYPE,a=Application.getAppConfig("HTTP_CONFIG").DATA_CARRYING;if(!t||!e)throw new Exception("ADAPTER Error","Bind http adapter error");Application.bindAdapter(t,e);const o=Application.getAdapter(t),c=Application.getAppConfig("HTTP_CONFIG").REQUEST_MIDDLEWARE,p=Application.getAppConfig("HTTP_CONFIG").RESPONSE_MIDDLEWARE;this.app.singleton("$request",()=>new HttpService(this.app,{HTTP_ADAPTER:o,HTTP_API:s,HTTP_HOST:i,IS_RESTFUL:r,CONTENT_TYPE:n,DATA_CARRYING:a,REQUEST_MIDDLEWARE:c,RESPONSE_MIDDLEWARE:p}))}}class EventBus{_events=new Map;static _instance;static getInstance(){return EventBus._instance&&EventBus._instance instanceof EventBus||(EventBus._instance=new EventBus),EventBus._instance}static getEvents(){return EventBus.getInstance()._events}static getEventsSize(){return EventBus.getInstance()._events.size}static getEvent(t){return EventBus.getInstance()._events.get(t)}static hasEvent(t){return EventBus.getInstance()._events.has(t)}static deleteEvent(t){return EventBus.getInstance()._events.delete(t),EventBus.hasEvent(t)}static setEvent(t,e){return EventBus.hasEvent(t),EventBus.getInstance()._events.set(t,e)}static on(t,e){return isFunction(e)||console.warn("The second argument to the on method must be a function"),EventBus.setEvent(t,e)}static emit(t,...e){if(isFunction(EventBus.getEvent(t)))return EventBus.getEvent(t)(...e);console.error(`You need to bind the ${t} event and method before emit`)}static once(t,...e){EventBus.emit(t,...e),EventBus.off(t)}static off(t){if(Array.isArray(t)){const e=t.map(t=>EventBus.off(t));return e.indexOf(!1)<0}return!!EventBus.hasEvent(t)&&EventBus.getInstance()._events.delete(t)}}function defineAppConfig(t){return t}function defineAppHttpConfig(t){return t}function defineHttpConfig(t){return t}function defineHttpApis(t){return t}const providers=[CommandProvider,HelperProvider,HttpProvider];Application.setProviders(providers);export{AxiosAdapter,Command,Container,EventBus,Exception,is as Is,Lib,ServiceProvider,Transformer,Application as default,defineAppConfig,defineAppHttpConfig,defineHttpApis,defineHttpConfig};
4
+ //# sourceMappingURL=ege.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ege.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,13 @@
1
+ import Application from "./core/Application";
2
+ import Exception from "./core/Libs/Exception";
3
+ import Container from "./core/Container/Container";
4
+ import Command from "./core/Command/Command";
5
+ import Transformer from "./core/Transformer/Transformer";
6
+ import Lib from "./core/Libs/Lib";
7
+ import AxiosAdapter from "./core/Contracts/AxiosAdapter";
8
+ import ServiceProvider from "./core/Provider/ServiceProvider";
9
+ import EventBus from "./core/Wrenches/EventBus";
10
+ import * as Is from "./core/Wrenches/is";
11
+ export * from "./core/TypeFunc";
12
+ export * from "./core/Type/types";
13
+ export { Application as default, Command, Container, ServiceProvider, Exception, Transformer, Lib, AxiosAdapter, EventBus, Is, };
@@ -0,0 +1,4 @@
1
+ import qs from"qs";class Exception extends Error{name="Error";message="Error message";code=500;constructor(t,e,s=500){super(e),this.name=t??"Error",this.message=e??"Error message",this.code=s??500}}class Lib{static typeOf(t,e){return typeof t===e}static getTag(t){return Object.prototype.toString.call(t)}static isFunction(t){return Lib.typeOf(t,"function")&&"[object Function]"===Lib.getTag(t)}static isString(t){return Lib.typeOf(t,"string")||"[object String]"===Lib.getTag(t)}static isNumber(t){return"number"==typeof t}static isObject(t){return"[object Object]"===Lib.getTag(t)}static isUndefined(t){return void 0===t||"[object Undefined]"===Lib.getTag(t)}static isNull(t){return null===t||"[object Null]"===Lib.getTag(t)}static isEmpty(t){return!t&&0!==t||!(!Lib.isObject(t)&&!Array.isArray(t))&&("{}"===JSON.stringify(t)||"[]"===JSON.stringify(t))}static isClass(t){if(Lib.isFunction(t)){const e=t.toString();if(void 0!==t.prototype&&t.prototype.constructor===t){if("class "===e.slice(0,6))return!0;if(2<=Object.getOwnPropertyNames(t.prototype).length)return!0;/^function\s+\(|^function\s+anonymous\(/.test(e)}}return!1}static strTrim(t,e,s){return e?"L"===s?t.replace(new RegExp("^\\"+e+"+","g"),""):"R"===s?t.replace(new RegExp("\\"+e+"+$","g"),""):t.replace(new RegExp("^\\"+e+"+|\\"+e+"+$","g"),""):t.replace(/^\s+|\s+$/g,"")}}class Container{static instance;instances=new Map;bindings={};aliases={};bind(t,e){if(!t)throw new Exception("Abstract Error","Abstract not null");if(Array.isArray(t))t.map(t=>{this.bind(t,e)});else{if(!Lib.isString(t))throw new Exception("Abstract Error","The abstract name is a string");Lib.isObject(e)||Lib.isClass(e)?this.bindings[t]=e:Lib.isFunction(e)&&!Lib.isClass(e)&&this.instances.set(t,e)}}make(t,e,s=!1){var i;if(t=this.getAlias(t),this.has(t))return i=this.instances.get(t)||this.bindings[t],Lib.isClass(i)?this.makeClass(t,i,e,s):Lib.isFunction(i)?this.makeFunc(t,i,e,s):i;throw new Exception("Container Error","The abstract does not exist")}makeClass(t,e,s,i=!1){var r=()=>new e(s);return i?(this.bind(t,r),this.instances.get(t)):r}makeFunc(t,e,s,i=!1){e=e(s);return i?(this.bind(t,e),this.instances.get(t)):e}has(t){return this.existence(t)}existence(t){return!this.bindings[t]||!this.instances.get(t)||!this.getAlias(t)}getAlias(t){return this.aliases[t]||t}get(t){if(this.has(t))return this.make(t);throw new Exception("Container Error","The abstract does not exist")}singleton(t,e){this.bind(t,e)}static getInstance(){let t=this.instance;return t=t&&t instanceof Container?t:this.instance=new Container}proxyInstance(){return new Proxy(this,{get:(t,e)=>t[e]})}}const opt=Object.prototype.toString;function isArray(t){return"[object Array]"===opt.call(t)}function isNull(t){return"[object Null]"===opt.call(t)}function isBoolean(t){return"[object Boolean]"===opt.call(t)}function isObject(t){return"[object Object]"===opt.call(t)}const isPromise=t=>"[object Promise]"===opt.call(t);function isString(t){return"[object String]"===opt.call(t)}function isNumber(t){return"[object Number]"===opt.call(t)&&t==t}function isRegExp(t){return"[object RegExp]"===opt.call(t)}function isDate(t){return"[object Date]"===opt.call(t)}function isHex(t){return/^#[a-fA-F0-9]{3}$|#[a-fA-F0-9]{6}$/.test(t)}function isRgb(t){return/^rgb\((\s*\d+\s*,?){3}\)$/.test(t)}function isRgba(t){return/^rgba\((\s*\d+\s*,\s*){3}\s*\d(\.\d+)?\s*\)$/.test(t)}function isColor(t){return isHex(t)||isRgb(t)||isRgba(t)}function isUndefined(t){return void 0===t}function isFunction(t){return"function"==typeof t}function isClass(t){if("function"==typeof t){const e=t.toString();if(void 0!==t.prototype&&t.prototype.constructor===t){if("class "===e.slice(0,6))return!0;if(2<=Object.getOwnPropertyNames(t.prototype).length)return!0;/^function\s+\(|^function\s+anonymous\(/.test(e)}}return!1}function isEmptyObject(t){return isObject(t)&&0===Object.keys(t).length}function isEmpty(t){return!t&&0!==t||isEmptyObject(t)}function isExist(t){return t||0===t}function isWindow(t){return t===window}function isPhone(t){return/^(13[0-9]|14[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9])[0-9]{8}$/.test(t)}function isEmail(t){return/^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(t)}var is=Object.freeze({__proto__:null,isArray:isArray,isNull:isNull,isBoolean:isBoolean,isObject:isObject,isPromise:isPromise,isString:isString,isNumber:isNumber,isRegExp:isRegExp,isDate:isDate,isColor:isColor,isUndefined:isUndefined,isFunction:isFunction,isClass:isClass,isEmptyObject:isEmptyObject,isEmpty:isEmpty,isExist:isExist,isWindow:isWindow,isPhone:isPhone,isEmail:isEmail}),name="pdd",version="0.3.23",description="PDD Framework",main="framework/umd/pdd.js",module="framework/es/pdd.js",typings="index.d.ts",repository={type:"git",url:"https://github.com/BDSaaS/zhima.git"},bugs={url:"https://github.com/BDSaaS/zhima/issues"},author="BDSaaS.com <xy@ztes.com>",blog="https://bdsaas.com",keywords=["framework","web framework","Typescript framework","pdd","pdd framework"],license="MIT",scripts={"build:pkg":"rollup --config rollup.config.js",create:"tsc",dev:"set NODE_ENV=developemnt&& rollup -c rollup.config.js -w",build:"rollup -c rollup.config.js","eslint:fix":"./node_modules/.bin/eslint --fix ./",publish:"npm publish --access=public","publish:yarn":"yarn publish --access=public"},devDependencies={"@babel/core":"^7.18.6","@babel/preset-env":"^7.15.8","@rollup/plugin-json":"^6.0.0","@types/node":"^18.7.6","@types/qs":"^6.9.7","@types/webpack-env":"^1.17.0","@typescript-eslint/eslint-plugin":"^5.59.2","@typescript-eslint/parser":"^5.0.0","core-js":"3",eslint:"^8.17.0","eslint-config-prettier":"^8.5.0","eslint-define-config":"^1.5.0","eslint-plugin-prettier":"^4.0.0",prettier:"^2.6.2",qs:"^6.11.0",rollup:"^2.79.1","rollup-plugin-babel":"^4.4.0","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-dts":"^4.2.2","rollup-plugin-eslint":"^7.0.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-typescript":"^1.0.1","rollup-plugin-typescript2":"^0.31.1","rollup-plugin-uglify":"^6.0.4",typescript:"^4.4.4"},files=["/framework","README.md","index.d.ts"],Package={name:name,version:version,description:description,main:main,module:module,typings:typings,repository:repository,bugs:bugs,author:author,blog:blog,keywords:keywords,license:license,scripts:scripts,devDependencies:devDependencies,files:files};class Application extends Container{static VERSION=Package.version;adapters=new WeakMap;providers=[];static lifecycle(){const t=(new Date).getTime();return{created:()=>{Application.registerProviders(Application.getProviders()),Application.registerProviders(Application.getConfig("APP_CONFIG").PROVIDERS)},mounted:()=>{},unmounted:()=>{console.log(`
2
+ %c pdd %c ${Application.VERSION} ${(new Date).getTime()-t}ms
3
+ `,"color: #fadfa3; background: #030307; padding:5px 0;border-radius:3px 0 0 3px;","color:#000000;background: #ebd29a; padding:5px 0;border-radius:0 3px 3px 0;")}}}getterProviders(){var t=this.providers;return Array.isArray(t)&&0<t.length?t:[]}static getProviders(){return Application.getInstance().getterProviders()}setterProviders(t){const e=this.providers;Array.isArray(e)&&(this.providers=e.filter(e=>{return!t.find(t=>e===t)}),this.providers=this.getterProviders().concat(t))}static setProviders(t){Application.getInstance().setterProviders(t)}static registerProvider(t){if(!isClass(t))throw new Exception("Provider Error","The first argument must be a class");new t(Application.getInstance()).register()}static registerProviders(t){Array.isArray(t)&&t.map(t=>{Application.registerProvider(t)})}static setConfig(t,e){Application.getInstance().singleton(t,e)}static getConfig(t,e){if(Application.getInstance().has(t))return Application.getInstance().get(t);if(isEmpty(e))throw new Exception("Application Config Error","Configuration information does not exist");return e}static setAppConfig(t){Application.setConfig("APP_CONFIG",t)}static getAppConfig(t){return Application.getConfig("APP_CONFIG",{})[t]}static bindAdapter(t,e){if(!isClass(t))throw new Exception("Adapter Error","The first argument must be a class");e=isEmpty(e)?new t:new t(e);Application.getInstance().setterAdapter(t,e)}setterAdapter(t,e){if(!isClass(t))throw new Exception("Adapter Error","The first argument must be a class");Application.getAdapter(t)&&console.warn("Adapter Warn",`The adapter ${t.name||""} is already bound`),this.adapters.set(t,e)}static getAdapter(t){if(isClass(t))return Application.getInstance().getterAdapter(t);throw new Exception("Adapter Error","The argument must be a class")}getterAdapter(t){return this.adapters.get(t)}static getService(t){return Application.getInstance().get(t)}static getInstance(){let t=Application.instance;return t=t&&t instanceof Application?t:Application.instance=new Application}static run(t){const e=Application.lifecycle();e.created(),e.mounted(),e.unmounted(),isFunction(t)&&t()}}class Command{payload;$helper;constructor(...t){this.payload=[...t],this.$helper=Application.getService("$helper")}}class Transformer{data;payload;constructor(t,e){this.data=t,this.payload=e}transform(t,e){return t}create(s){return Array.isArray(this.data)?this.data.map((t,e)=>Lib.isFunction(s)?s(t,e):this.transform(t)):Lib.isFunction(s)?s(this.data,0):this.transform(this.data)}formatNumber(t,e=-1,s="",i="."){"number"!=typeof t&&(t=Lib.typeOf(t,"string")?parseFloat(t):0);var r=(t=isNaN(t)?0:t).toString().split("."),r=(e=parseInt(e),e=isNaN(Math.abs(e))||-1===e?-1:Math.abs(e),r[1]&&-1===e?e=r[1].length:r[1]||-1!==e||(e=0),s="string"==typeof s?s:",",i=i||".",t<0?"-":"");let n,a;return n=parseInt(t=Math.abs(+t||0).toFixed(e),10).toString(),r+((a=3<(a=n.length)?a%3:0)?n.substr(0,a)+s:"")+n.substr(a).replace(/(\d{3})(?=\d)/g,"$1"+s)+(e?i+Math.abs(Number(t)-Number(n)).toFixed(e).slice(2):"")}formatDate(t=Date.now()){if(Lib.typeOf(t,"string"))return isNaN(Date.parse(t))?this.formatDate():this.formatDate(Date.parse(t));const e=new Date(t),s=e.getFullYear(),i=e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,r=e.getDate()<10?"0"+e.getDate():e.getDate(),n=e.getHours()<10?"0"+e.getHours():e.getHours(),a=e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes(),o=e.getSeconds()<10?"0"+e.getSeconds():e.getSeconds();var t=e.getDay(),c=0<=e.getHours()&&n<12?"AM":"PM",p=0<=e.getHours()&&n<12?"上午":"下午";return{Y:s.toString(),M:i.toString(),D:r.toString(),h:n.toString(),m:a.toString(),s:o.toString(),week:["日","一","二","三","四","五","六"][t],ap:c,apCn:p}}}class HttpAdapterInterface{http;method="POST";url="";data={};headers={};constructor(t){if("function"!=typeof t)throw new Exception("HTTP Adapter Error","The first argument must be a function");this.http=t}setConfig({method:t,url:e,data:s,headers:i}){this.method=t??this.method,this.url=e??this.url,this.data=s??this.data,this.headers=i??this.headers}request(){return new Promise((e,s)=>{this.http({method:this.method,url:this.url,data:this.data,headers:this.headers}).then(t=>{e(t)}).catch(t=>{s(t)})})}}class AxiosAdapter extends HttpAdapterInterface{request(){return new Promise((e,s)=>{this.http({method:this.method,url:this.url,data:this.data,headers:this.headers}).then(t=>{e(t)}).catch(t=>{s(t)})})}}class ServiceProvider{app;constructor(t){this.app=t,this.register()}register(){console.log("Service is already registered")}}class CommandProvider extends ServiceProvider{register(){this.app.singleton("$command",()=>{console.log("COMMAND_REGISTERED")})}}class WebStorage{type="localStorage";storage="localStorage"===this.type?localStorage:sessionStorage;constructor({type:t}){this.setConfig({type:t})}get(t){if(!t)return this.getAll();if(Lib.isString(t))return this.storage.getItem(t);throw new Exception("","The first parameter is a string")}set(t,e){if("length"===t)throw new Exception("WebStorage Error","The key of data must not be length");this.storage.setItem(t,JSON.stringify(e))}save(t,e){this.set(t,e)}delete(t){t?Array.isArray(t)?t.map(t=>{this.delete(t)}):this.storage.removeItem(t):this.clear()}remove(t){this.delete(t)}clear(){this.storage.clear()}keys(){var t=this.getAll();return Object.keys(t)}getAll(){const{length:t,...e}=this.storage;return e}setConfig({type:t}){this.type=t}}class Service{app;constructor(t){this.app=t}}class Helper extends Service{env(){return{}}webStorage(t,e,s){const i=new WebStorage({type:t});if(e&&!Lib.isString(e))throw new Exception("WebStorage Error","The first argument must be a string");return void 0!==e||Lib.isString(e)?void 0===s?i.get(e):void i.save(e,s):i.getAll()}storage(t,e){return this.webStorage("localStorage",t,e)}cookie(){}session(t,e){return this.webStorage("sessionStorage",t,e)}async http(t,e,s={}){try{return await Application.getService("$request").http(t,e,s)}catch(t){new Exception("HttpError","")}}async send(t,e,s,i,r=!0){if(!this.app.has("$request"))throw new Exception("RequestService Error","");let n=await Application.getService("$request").send(t,e,i,r);return Lib.isFunction(s)&&(n=s(n)),r?n:n.data}checkAuth(){}cookies(t,e){}request(t,e,s){}}class HelperProvider extends ServiceProvider{register(){this.app.singleton("$helper",()=>new Helper(this.app))}}class RESTful{isRESTful=!0;api;requestData;constructor(t,e,s){this.isRESTful=s??this.isRESTful,this.api=t,this.requestData=e}create(){return this.isRESTful?this.transformer():{api:this.api,data:this.requestData}}transformer(){let t=Object.keys(this.requestData),i={},r={},e=(t.map(t=>{var e=t.match(/^__/g),s=t.replace(/^__/g,"");e?i[s]=this.requestData[t]:r[s]=this.requestData[t]}),this.api.match(/<(.*?)>/g)),s={};if(e&&Array.isArray(e)){let t=e.map(t=>{let e=t.replace(/(^<)|(>$)/g,"");t=e.split("=");return 2===t.length?(s[t[0]]=t[1],t[0]):(s[e]=null,e)});return Object.assign(s,i),this.api=this.api.replace(/=(.*?)>/g,">"),t.map(t=>{this.api=this.api.replace(`<${t}>`,s[t])}),{api:this.api,data:r}}return{api:this.api,data:this.requestData}}}class HttpService extends Service{_http=null;_api={};_headers={};_host="";_isRESTful=!0;_carryingData={};_mode="REQUEST_PAYLOAD";$helper=null;_requestMiddleware;_responseMiddleware;_context={request:{hairstyle:null,body:null},response:null};constructor(t,{HTTP_ADAPTER:e,HTTP_API:s,HTTP_HOST:i,IS_RESTFUL:r,CONTENT_TYPE:n,DATA_CARRYING:a,REQUEST_MIDDLEWARE:o,RESPONSE_MIDDLEWARE:c}){super(t),this._http=e??this._http,this._api=s??this._api,this._host=i??this._host,this._isRESTful=r??!0,this.setContentType(n),this.setDataCarry(a.REQUEST_HEADERS,a.REQUEST_DATA),this._requestMiddleware=isFunction(o)?o:t=>t,this._responseMiddleware=isFunction(c)?c:t=>t}setContentType(t){"REQUEST_PAYLOAD"===t?(this._mode=t,this.setHeader("Content-Type","application/json")):"FORM_DATA"===t&&(this._mode=t,this.setHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"))}setDataCarry(e,s){if(e){const t=Object.keys(e);Array.isArray(t)&&t.map(t=>{this.carryingHandle(t,e[t],"REQUEST_HEADERS")})}if(s){const i=Object.keys(s);Array.isArray(i)&&i.map(t=>{this.carryingHandle(t,s[t],"REQUEST_DATA")})}}carryingHandle(e,s,i="REQUEST_HEADERS"){if(e&&s)if(isFunction(s))try{"REQUEST_HEADERS"===i?this.setHeader(e,s()):"REQUEST_DATA"===i&&this.setData(e,s())}catch(t){console.warn("Application Error",t)}else{let t=null;"LOCAL"===s?t=Application.getService("$helper").storage(e):"SESSION"===s?t=Application.getService("$helper").session(e):"COOKIES"===s?t=Application.getService("$helper").cookies(e):"STORAGE"===s&&(t=Application.getService("$helper").storage(e)),"REQUEST_HEADERS"===i?this.setHeader(e,t):"REQUEST_DATA"===i&&this.setData(e,t)}}async http(t,e,s){try{var i=this.getParameters(t,e);this.setContentType(i.type),this._context.request={...this._context.request,headers:this._headers,...i},this._context.request.headers={...this._context.request.headers,...s},this._context=this._requestMiddleware(this._context),this._context.request.headers={...this._context.request.headers,...s},this._http.setConfig(this._context.request)}catch(t){console.warn("Request config warn",t)}try{return await this.request(this._context.request.hairstyle[3])}catch(t){console.warn("Request interceptor warn",t)}}async request(t){try{var e=await this._http.request();try{this._context.response=e;var s=await this._responseMiddleware(this._context);return t?s.response:s.response.data}catch(t){console.warn("Response middleware Error",t)}}catch(t){if(t&&t.response)switch(t.response.status){case 400:t.message="请求参数错误";break;case 401:t.message="未授权,请登录";break;case 403:t.message="跨域拒绝访问";break;case 404:t.message="请求地址出错: "+t.response.config.url;break;case 408:t.message="请求超时";break;case 500:t.message="服务器内部错误";break;case 501:t.message="服务未实现";break;case 502:t.message="网关错误";break;case 503:t.message="服务不可用";break;case 504:t.message="网关超时";break;case 505:t.message="HTTP版本不受支持"}throw this._context.response={...t.response,message:t.message},this._responseMiddleware(this._context),t}}async send(t,e,s={},i=!1){s.host&&(this._host=s.host),s.headers&&this.setHeaders(s.headers),s.mode&&this.setContentType(s.mode);const r=this.makeHairstyle(t);return i&&(r[3]=i),this.http(r,e,{})}makeHairstyle(t){let e;if(!(e="string"==typeof t?this._api[t]:t)&&!t)throw new Exception("The api route does not exist","ApiRouteError");t=e[0];let s=["POST","REQUEST_PAYLOAD"];var i=e[2]||!0,r=e[3]||!1;return(s="string"==typeof e[1]?[e[1]||"POST",this._mode]:Array.isArray(e[1])?[e[1][0]||"POST",e[1][1]||this._mode]:["POST",this._mode])[0]=s[0].toUpperCase(),[t,s,i,r]}getParameters(t,e){var[t,s,i,r]=this.makeHairstyle(t),n={...this._carryingData,...e};const a=new RESTful(t,n,this._isRESTful).create();let o=Lib.strTrim(this._host,"/")+"/"+Lib.strTrim(a.api,"/");return"FORM_DATA"===s?.[1]&&(a.data=qs.stringify(a.data)),"GET"===s?.[0]&&(this.deleteHeader("Content-Type"),isObject(a.data)&&"REQUEST_PAYLOAD"===this._mode?o=o+"?"+qs.stringify(a.data):a.data&&"FORM_DATA"===this._mode&&(o=o+"?"+a.data)),{api:a.api.trim(),url:o,method:s?.[0],type:s?.[1],data:a.data,auth:i,hairstyle:[t,s,i,r],body:e,payload:a.data}}setHeaders(t={}){this._headers={...this._headers,...t}}getHeaders(){return this._headers}setHeader(t,e){this._headers[t]=e}deleteHeader(t){delete this._headers[t]}setData(t,e){this._carryingData[t]=e}}class HttpProvider extends ServiceProvider{register(){var t=Application.getAppConfig("HTTP_CONFIG").HTTP_ADAPTER,e=Application.getAppConfig("HTTP_CONFIG").HTTP_LIB;const s=Application.getAppConfig("HTTP_CONFIG").HTTP_API,i=Application.getAppConfig("HTTP_CONFIG").HTTP_HOST,r=Application.getAppConfig("HTTP_CONFIG").IS_RESTFUL,n=Application.getAppConfig("HTTP_CONFIG").CONTENT_TYPE,a=Application.getAppConfig("HTTP_CONFIG").DATA_CARRYING;if(!t||!e)throw new Exception("ADAPTER Error","Bind http adapter error");Application.bindAdapter(t,e);const o=Application.getAdapter(t),c=Application.getAppConfig("HTTP_CONFIG").REQUEST_MIDDLEWARE,p=Application.getAppConfig("HTTP_CONFIG").RESPONSE_MIDDLEWARE;this.app.singleton("$request",()=>new HttpService(this.app,{HTTP_ADAPTER:o,HTTP_API:s,HTTP_HOST:i,IS_RESTFUL:r,CONTENT_TYPE:n,DATA_CARRYING:a,REQUEST_MIDDLEWARE:c,RESPONSE_MIDDLEWARE:p}))}}class EventBus{_events=new Map;static _instance;static getInstance(){return EventBus._instance&&EventBus._instance instanceof EventBus||(EventBus._instance=new EventBus),EventBus._instance}static getEvents(){return EventBus.getInstance()._events}static getEventsSize(){return EventBus.getInstance()._events.size}static getEvent(t){return EventBus.getInstance()._events.get(t)}static hasEvent(t){return EventBus.getInstance()._events.has(t)}static deleteEvent(t){return EventBus.getInstance()._events.delete(t),EventBus.hasEvent(t)}static setEvent(t,e){return EventBus.hasEvent(t),EventBus.getInstance()._events.set(t,e)}static on(t,e){return isFunction(e)||console.warn("The second argument to the on method must be a function"),EventBus.setEvent(t,e)}static emit(t,...e){if(isFunction(EventBus.getEvent(t)))return EventBus.getEvent(t)(...e);console.error(`You need to bind the ${t} event and method before emit`)}static once(t,...e){EventBus.emit(t,...e),EventBus.off(t)}static off(t){if(Array.isArray(t)){const e=t.map(t=>EventBus.off(t));return e.indexOf(!1)<0}return!!EventBus.hasEvent(t)&&EventBus.getInstance()._events.delete(t)}}function defineAppConfig(t){return t}function defineAppHttpConfig(t){return t}function defineHttpConfig(t){return t}function defineHttpApis(t){return t}function defineHttpRequestConfig(t){return t}const providers=[CommandProvider,HelperProvider,HttpProvider];Application.setProviders(providers);export{AxiosAdapter,Command,Container,EventBus,Exception,is as Is,Lib,ServiceProvider,Transformer,Application as default,defineAppConfig,defineAppHttpConfig,defineHttpApis,defineHttpConfig,defineHttpRequestConfig};
4
+ //# sourceMappingURL=pdd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}