@pisell/core 1.0.21 → 1.0.23

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/es/app/app.d.ts CHANGED
@@ -35,7 +35,7 @@ declare class App {
35
35
  locales: Locales;
36
36
  models: {
37
37
  getStore: () => import("../models").Store;
38
- StoreProvider: typeof import("react-redux").Provider;
38
+ StoreProvider: any;
39
39
  setConfig: (models: any[]) => void;
40
40
  };
41
41
  request: {
package/es/aws/index.d.ts CHANGED
@@ -11,6 +11,6 @@ declare class AWS {
11
11
  private app;
12
12
  private config?;
13
13
  constructor(app: App, options?: AWSOptions);
14
- upload(params: UploadParams): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
14
+ upload(params: UploadParams): Promise<any>;
15
15
  }
16
16
  export default AWS;
@@ -1,14 +1,13 @@
1
1
  import type { History as HistoryType } from "history";
2
- import { useHistory, useLocation, useParams } from "react-router-dom";
3
2
  import App from "../app";
4
3
  export interface HistoryOptions {
5
4
  basename?: string;
6
5
  }
7
6
  export declare class History {
8
- instance: HistoryType<unknown>;
9
- useHistory: typeof useHistory;
10
- useLocation: typeof useLocation;
11
- useParams: typeof useParams;
7
+ instance: any;
8
+ useHistory: any;
9
+ useLocation: any;
10
+ useParams: any;
12
11
  app: App;
13
12
  constructor(app: App, options?: HistoryOptions);
14
13
  push: HistoryType["push"];
@@ -14,4 +14,4 @@ export declare const MenuProvider: React.FC<{
14
14
  children: React.ReactNode;
15
15
  menus: MenuItem[];
16
16
  }>;
17
- export declare const useMenu: () => MenuContextType;
17
+ export declare const useMenu: () => any;
@@ -12,7 +12,7 @@ export declare class MenuManager {
12
12
  private menuItems;
13
13
  private menuMaps;
14
14
  private app;
15
- useMenu: () => import("./hooks").MenuContextType;
15
+ useMenu: () => any;
16
16
  MenuProvider: React.FC<{
17
17
  children: React.ReactNode;
18
18
  menus: MenuItem[];
@@ -1,5 +1,4 @@
1
1
  import hooks from '../hooks';
2
- import { Provider as StoreProvider } from "react-redux";
3
2
  declare const models: import("./global").GlobalModal[];
4
3
  declare type ModalsType = (typeof models[number]);
5
4
  export interface Store {
@@ -39,7 +38,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
39
38
  declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
40
39
  declare const _default: {
41
40
  getStore: () => Store;
42
- StoreProvider: typeof StoreProvider;
41
+ StoreProvider: any;
43
42
  setConfig: (models: any[]) => void;
44
43
  };
45
44
  export default _default;
@@ -28,6 +28,16 @@ declare class PubSub {
28
28
  * @param args 事件参数
29
29
  */
30
30
  publish(event: string, ...args: any[]): void;
31
+ /**
32
+ * @title: 异步发布, 某些事件需要延迟发布
33
+ * @description:
34
+ * @param {string} event
35
+ * @param {number} timeout
36
+ * @param {array} args
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ */
40
+ publishDelay(event: string, delay?: number, ...args: any[]): void;
31
41
  /**
32
42
  * 移除某个事件的所有订阅
33
43
  * @param event 事件名称
@@ -77,6 +77,28 @@ var PubSub = /*#__PURE__*/function () {
77
77
  });
78
78
  }
79
79
 
80
+ /**
81
+ * @title: 异步发布, 某些事件需要延迟发布
82
+ * @description:
83
+ * @param {string} event
84
+ * @param {number} timeout
85
+ * @param {array} args
86
+ * @return {*}
87
+ * @Author: zhiwei.Wang
88
+ */
89
+ }, {
90
+ key: "publishDelay",
91
+ value: function publishDelay(event) {
92
+ var _this2 = this;
93
+ var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
94
+ for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
95
+ args[_key2 - 2] = arguments[_key2];
96
+ }
97
+ setTimeout(function () {
98
+ _this2.publish.apply(_this2, [event].concat(args));
99
+ }, delay);
100
+ }
101
+
80
102
  /**
81
103
  * 移除某个事件的所有订阅
82
104
  * @param event 事件名称
@@ -129,9 +151,9 @@ var PubSub = /*#__PURE__*/function () {
129
151
  }, {
130
152
  key: "once",
131
153
  value: function once(event, callback) {
132
- var _this2 = this;
154
+ var _this3 = this;
133
155
  var wrappedCallback = function wrappedCallback() {
134
- _this2.unsubscribe(event, wrappedCallback);
156
+ _this3.unsubscribe(event, wrappedCallback);
135
157
  callback.apply(void 0, arguments);
136
158
  };
137
159
  return this.subscribe(event, wrappedCallback);
@@ -32,7 +32,7 @@ export declare const getCacheData: (url: string, data: any, cache: CacheProps) =
32
32
  * @return {*}
33
33
  * @Author: zhiwei.Wang
34
34
  */
35
- export declare const setCacheData: (url: string, data: any, res: any, cache: CacheProps) => any | null;
35
+ export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
36
  /**
37
37
  * @title: 缓存函数包装器
38
38
  * @description:
@@ -124,20 +124,26 @@ var getCache = /*#__PURE__*/function () {
124
124
  case 0:
125
125
  _getConfig3 = getConfig(), storage = _getConfig3.storage; // 如果 当前时间 - 数据缓存时间 小于 超时时间, 则数据正常.
126
126
  if (!(cache.type === 'memory')) {
127
- _context2.next = 6;
127
+ _context2.next = 8;
128
128
  break;
129
129
  }
130
- if (!getIsEffectiveTime(CACHES[key].time)) {
130
+ if (CACHES[key]) {
131
131
  _context2.next = 4;
132
132
  break;
133
133
  }
134
- return _context2.abrupt("return", CACHES[key].data);
134
+ return _context2.abrupt("return", null);
135
135
  case 4:
136
- _context2.next = 21;
137
- break;
136
+ if (!getIsEffectiveTime(CACHES[key].time)) {
137
+ _context2.next = 6;
138
+ break;
139
+ }
140
+ return _context2.abrupt("return", CACHES[key].data);
138
141
  case 6:
142
+ _context2.next = 23;
143
+ break;
144
+ case 8:
139
145
  if (!(cache.type === 'storage')) {
140
- _context2.next = 13;
146
+ _context2.next = 15;
141
147
  break;
142
148
  }
143
149
  storageDetail = storage.getStorage(key) || "";
@@ -145,35 +151,35 @@ var getCache = /*#__PURE__*/function () {
145
151
  storageDetail = JSON.parse(storageDetail);
146
152
  }
147
153
  if (!getIsEffectiveTime(storageDetail.time)) {
148
- _context2.next = 11;
154
+ _context2.next = 13;
149
155
  break;
150
156
  }
151
157
  return _context2.abrupt("return", (_storageDetail = storageDetail) === null || _storageDetail === void 0 ? void 0 : _storageDetail.data);
152
- case 11:
153
- _context2.next = 21;
154
- break;
155
158
  case 13:
159
+ _context2.next = 23;
160
+ break;
161
+ case 15:
156
162
  if (!(cache.type === 'indexDB')) {
157
- _context2.next = 21;
163
+ _context2.next = 23;
158
164
  break;
159
165
  }
160
166
  app = getApp();
161
167
  if (!app.dbManager) {
162
- _context2.next = 21;
168
+ _context2.next = 23;
163
169
  break;
164
170
  }
165
- _context2.next = 18;
171
+ _context2.next = 20;
166
172
  return app.dbManager.get('requests', key);
167
- case 18:
173
+ case 20:
168
174
  indexDBDetail = _context2.sent;
169
175
  if (!indexDBDetail) {
170
- _context2.next = 21;
176
+ _context2.next = 23;
171
177
  break;
172
178
  }
173
179
  return _context2.abrupt("return", indexDBDetail === null || indexDBDetail === void 0 ? void 0 : indexDBDetail.data);
174
- case 21:
180
+ case 23:
175
181
  return _context2.abrupt("return", null);
176
- case 22:
182
+ case 24:
177
183
  case "end":
178
184
  return _context2.stop();
179
185
  }
@@ -251,7 +257,10 @@ export var getCacheData = /*#__PURE__*/function () {
251
257
  * @return {*}
252
258
  * @Author: zhiwei.Wang
253
259
  */
254
- export var setCacheData = function setCacheData(url, data, res, cache) {
260
+ export var setCacheData = function setCacheData(url, data, res) {
261
+ var cache = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
262
+ type: 'memory'
263
+ };
255
264
  // 创建缓存key
256
265
  var _key = createCacheKey(url, data, cache);
257
266
  setCache(_key, res, cache);
@@ -269,37 +278,44 @@ export var setCacheData = function setCacheData(url, data, res, cache) {
269
278
  */
270
279
  export var cacheFn = /*#__PURE__*/function () {
271
280
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(props, fn) {
272
- var url, data, config, _data, _config$cache;
281
+ var url, data, config, cache, _data, _config$cache;
273
282
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
274
283
  while (1) switch (_context4.prev = _context4.next) {
275
284
  case 0:
276
285
  url = props.url, data = props.data, config = props.config;
277
- if (!(config !== null && config !== void 0 && config.cache)) {
278
- _context4.next = 8;
286
+ if (!(config !== null && config !== void 0 && config.cache || config !== null && config !== void 0 && config.useCache)) {
287
+ _context4.next = 10;
279
288
  break;
280
289
  }
281
- _context4.next = 4;
282
- return getCacheData(url, data, config.cache);
283
- case 4:
290
+ cache = config.cache;
291
+ if (config.useCache) {
292
+ cache = {
293
+ type: 'memory'
294
+ };
295
+ }
296
+ // 获取缓存数据
297
+ _context4.next = 6;
298
+ return getCacheData(url, data, cache);
299
+ case 6:
284
300
  _data = _context4.sent;
285
301
  if (!_data) {
286
- _context4.next = 8;
302
+ _context4.next = 10;
287
303
  break;
288
304
  }
289
305
  // 如果开启更新缓存执行函数
290
306
  if ((_config$cache = config.cache) !== null && _config$cache !== void 0 && _config$cache.updateCache) {
291
307
  fn(_objectSpread(_objectSpread({}, props), {}, {
292
308
  config: _objectSpread(_objectSpread({}, props.config), {}, {
293
- cache: _objectSpread(_objectSpread({}, props.config.cache), {}, {
309
+ cache: _objectSpread(_objectSpread({}, cache), {}, {
294
310
  updateCache: false
295
311
  })
296
312
  })
297
313
  }));
298
314
  }
299
315
  return _context4.abrupt("return", _data);
300
- case 8:
316
+ case 10:
301
317
  return _context4.abrupt("return", fn(props));
302
- case 9:
318
+ case 11:
303
319
  case "end":
304
320
  return _context4.stop();
305
321
  }
@@ -128,7 +128,7 @@ export var requestCallback = function requestCallback(resData) {
128
128
  if (codeFn) {
129
129
  if ((res === null || res === void 0 ? void 0 : res.code) === 200) {
130
130
  // 需要缓存的进行缓存数据
131
- if (config !== null && config !== void 0 && config.cache) {
131
+ if (config !== null && config !== void 0 && config.useCache || config !== null && config !== void 0 && config.cache) {
132
132
  var _config$cacheUpdateCh;
133
133
  setCacheData(props.url, props.data, res, config === null || config === void 0 ? void 0 : config.cache);
134
134
  config === null || config === void 0 || (_config$cacheUpdateCh = config.cacheUpdateChange) === null || _config$cacheUpdateCh === void 0 || _config$cacheUpdateCh.call(config, res);
@@ -20,9 +20,9 @@ export declare class RouterManager {
20
20
  get(name: string): RouteType;
21
21
  has(name: string): boolean;
22
22
  remove(name: string): void;
23
- renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): any;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): JSX.Element[];
27
+ }): any[];
28
28
  }
@@ -7,7 +7,7 @@ export declare class TasksManager {
7
7
  private app;
8
8
  private db;
9
9
  useTasks: () => {
10
- tasks: TasksModule;
10
+ tasks: any;
11
11
  };
12
12
  watchTaskCallback: (taskModule: TasksModule) => void;
13
13
  private timerIds;
@@ -1,5 +1,4 @@
1
- import { TasksModule } from './type';
2
1
  declare const useTasks: () => {
3
- tasks: TasksModule;
2
+ tasks: any;
4
3
  };
5
4
  export default useTasks;
package/lib/app/app.d.ts CHANGED
@@ -35,7 +35,7 @@ declare class App {
35
35
  locales: Locales;
36
36
  models: {
37
37
  getStore: () => import("../models").Store;
38
- StoreProvider: typeof import("react-redux").Provider;
38
+ StoreProvider: any;
39
39
  setConfig: (models: any[]) => void;
40
40
  };
41
41
  request: {
@@ -11,6 +11,6 @@ declare class AWS {
11
11
  private app;
12
12
  private config?;
13
13
  constructor(app: App, options?: AWSOptions);
14
- upload(params: UploadParams): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | undefined>;
14
+ upload(params: UploadParams): Promise<any>;
15
15
  }
16
16
  export default AWS;
@@ -1,14 +1,13 @@
1
1
  import type { History as HistoryType } from "history";
2
- import { useHistory, useLocation, useParams } from "react-router-dom";
3
2
  import App from "../app";
4
3
  export interface HistoryOptions {
5
4
  basename?: string;
6
5
  }
7
6
  export declare class History {
8
- instance: HistoryType<unknown>;
9
- useHistory: typeof useHistory;
10
- useLocation: typeof useLocation;
11
- useParams: typeof useParams;
7
+ instance: any;
8
+ useHistory: any;
9
+ useLocation: any;
10
+ useParams: any;
12
11
  app: App;
13
12
  constructor(app: App, options?: HistoryOptions);
14
13
  push: HistoryType["push"];
@@ -14,4 +14,4 @@ export declare const MenuProvider: React.FC<{
14
14
  children: React.ReactNode;
15
15
  menus: MenuItem[];
16
16
  }>;
17
- export declare const useMenu: () => MenuContextType;
17
+ export declare const useMenu: () => any;
@@ -12,7 +12,7 @@ export declare class MenuManager {
12
12
  private menuItems;
13
13
  private menuMaps;
14
14
  private app;
15
- useMenu: () => import("./hooks").MenuContextType;
15
+ useMenu: () => any;
16
16
  MenuProvider: React.FC<{
17
17
  children: React.ReactNode;
18
18
  menus: MenuItem[];
@@ -1,5 +1,4 @@
1
1
  import hooks from '../hooks';
2
- import { Provider as StoreProvider } from "react-redux";
3
2
  declare const models: import("./global").GlobalModal[];
4
3
  declare type ModalsType = (typeof models[number]);
5
4
  export interface Store {
@@ -39,7 +38,7 @@ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T
39
38
  declare const setDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key: any, value: any) => void;
40
39
  declare const _default: {
41
40
  getStore: () => Store;
42
- StoreProvider: typeof StoreProvider;
41
+ StoreProvider: any;
43
42
  setConfig: (models: any[]) => void;
44
43
  };
45
44
  export default _default;
@@ -28,6 +28,16 @@ declare class PubSub {
28
28
  * @param args 事件参数
29
29
  */
30
30
  publish(event: string, ...args: any[]): void;
31
+ /**
32
+ * @title: 异步发布, 某些事件需要延迟发布
33
+ * @description:
34
+ * @param {string} event
35
+ * @param {number} timeout
36
+ * @param {array} args
37
+ * @return {*}
38
+ * @Author: zhiwei.Wang
39
+ */
40
+ publishDelay(event: string, delay?: number, ...args: any[]): void;
31
41
  /**
32
42
  * 移除某个事件的所有订阅
33
43
  * @param event 事件名称
@@ -74,6 +74,20 @@ var PubSub = class {
74
74
  }
75
75
  });
76
76
  }
77
+ /**
78
+ * @title: 异步发布, 某些事件需要延迟发布
79
+ * @description:
80
+ * @param {string} event
81
+ * @param {number} timeout
82
+ * @param {array} args
83
+ * @return {*}
84
+ * @Author: zhiwei.Wang
85
+ */
86
+ publishDelay(event, delay = 0, ...args) {
87
+ setTimeout(() => {
88
+ this.publish(event, ...args);
89
+ }, delay);
90
+ }
77
91
  /**
78
92
  * 移除某个事件的所有订阅
79
93
  * @param event 事件名称
@@ -32,7 +32,7 @@ export declare const getCacheData: (url: string, data: any, cache: CacheProps) =
32
32
  * @return {*}
33
33
  * @Author: zhiwei.Wang
34
34
  */
35
- export declare const setCacheData: (url: string, data: any, res: any, cache: CacheProps) => any | null;
35
+ export declare const setCacheData: (url: string, data: any, res: any, cache?: CacheProps) => any | null;
36
36
  /**
37
37
  * @title: 缓存函数包装器
38
38
  * @description:
@@ -77,6 +77,9 @@ var getIsEffectiveTime = (time) => {
77
77
  var getCache = async (key, cache) => {
78
78
  const { storage } = (0, import_config.getConfig)();
79
79
  if (cache.type === "memory") {
80
+ if (!CACHES[key]) {
81
+ return null;
82
+ }
80
83
  if (getIsEffectiveTime(CACHES[key].time)) {
81
84
  return CACHES[key].data;
82
85
  }
@@ -122,15 +125,23 @@ var getCacheData = async (url, data, cache) => {
122
125
  const res = await getCache(_key, cache);
123
126
  return res;
124
127
  };
125
- var setCacheData = (url, data, res, cache) => {
128
+ var setCacheData = (url, data, res, cache = {
129
+ type: "memory"
130
+ }) => {
126
131
  let _key = createCacheKey(url, data, cache);
127
132
  setCache(_key, res, cache);
128
133
  };
129
134
  var cacheFn = async (props, fn) => {
130
135
  var _a;
131
136
  const { url, data, config } = props;
132
- if (config == null ? void 0 : config.cache) {
133
- let _data = await getCacheData(url, data, config.cache);
137
+ if ((config == null ? void 0 : config.cache) || (config == null ? void 0 : config.useCache)) {
138
+ let cache = config.cache;
139
+ if (config.useCache) {
140
+ cache = {
141
+ type: "memory"
142
+ };
143
+ }
144
+ let _data = await getCacheData(url, data, cache);
134
145
  if (_data) {
135
146
  if ((_a = config.cache) == null ? void 0 : _a.updateCache) {
136
147
  fn({
@@ -138,7 +149,7 @@ var cacheFn = async (props, fn) => {
138
149
  config: {
139
150
  ...props.config,
140
151
  cache: {
141
- ...props.config.cache,
152
+ ...cache,
142
153
  updateCache: false
143
154
  }
144
155
  }
@@ -86,7 +86,7 @@ var requestCallback = (resData) => {
86
86
  const codeFn = requestCallbacks == null ? void 0 : requestCallbacks[res == null ? void 0 : res.code];
87
87
  if (codeFn) {
88
88
  if ((res == null ? void 0 : res.code) === 200) {
89
- if (config == null ? void 0 : config.cache) {
89
+ if ((config == null ? void 0 : config.useCache) || (config == null ? void 0 : config.cache)) {
90
90
  (0, import_cache.setCacheData)(props.url, props.data, res, config == null ? void 0 : config.cache);
91
91
  (_a = config == null ? void 0 : config.cacheUpdateChange) == null ? void 0 : _a.call(config, res);
92
92
  }
@@ -20,9 +20,9 @@ export declare class RouterManager {
20
20
  get(name: string): RouteType;
21
21
  has(name: string): boolean;
22
22
  remove(name: string): void;
23
- renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): any;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): JSX.Element[];
27
+ }): any[];
28
28
  }
@@ -7,7 +7,7 @@ export declare class TasksManager {
7
7
  private app;
8
8
  private db;
9
9
  useTasks: () => {
10
- tasks: TasksModule;
10
+ tasks: any;
11
11
  };
12
12
  watchTaskCallback: (taskModule: TasksModule) => void;
13
13
  private timerIds;
@@ -1,5 +1,4 @@
1
- import { TasksModule } from './type';
2
1
  declare const useTasks: () => {
3
- tasks: TasksModule;
2
+ tasks: any;
4
3
  };
5
4
  export default useTasks;
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
+ "scripts": {
5
+ "build": "father build",
6
+ "dev": "father dev",
7
+ "build:types": "tsc --project tsconfig.types.json",
8
+ "publish:types": "npm run build:types && cd types && cp ../types-package.json package.json && npm publish"
9
+ },
4
10
  "sideEffects": false,
5
11
  "main": "./lib/index.js",
6
12
  "module": "./es/index.js",
@@ -38,11 +44,5 @@
38
44
  ],
39
45
  "publishConfig": {
40
46
  "access": "public"
41
- },
42
- "scripts": {
43
- "build": "father build",
44
- "dev": "father dev",
45
- "build:types": "tsc --project tsconfig.types.json",
46
- "publish:types": "npm run build:types && cd types && cp ../types-package.json package.json && npm publish"
47
47
  }
48
48
  }