@pisell/core 1.0.46 → 1.0.47

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 (67) hide show
  1. package/es/app/index.d.ts +1 -1
  2. package/es/cmd/const.d.ts +5 -5
  3. package/es/hooks/useStore/index.d.ts +1 -1
  4. package/es/indexDB/index.js +28 -24
  5. package/es/locales/type.d.ts +3 -3
  6. package/es/logger/index.js +3 -2
  7. package/es/models/index.d.ts +4 -4
  8. package/es/pubsub/index.d.ts +1 -1
  9. package/es/request/cache.d.ts +1 -1
  10. package/es/request/pisell2Request.d.ts +1 -1
  11. package/es/routes/index.d.ts +2 -2
  12. package/es/socket/types.d.ts +1 -1
  13. package/es/tasks/type.d.ts +4 -4
  14. package/es/variables/index.d.ts +3 -3
  15. package/lib/app/index.d.ts +1 -1
  16. package/lib/aws/index.js +3 -0
  17. package/lib/cmd/const.d.ts +5 -5
  18. package/lib/cmd/const.js +5 -5
  19. package/lib/cmd/index.js +2 -0
  20. package/lib/cookie/index.js +2 -4
  21. package/lib/data/index.js +3 -0
  22. package/lib/hooks/useStore/index.d.ts +1 -1
  23. package/lib/indexDB/index.js +18 -17
  24. package/lib/locales/index.js +95 -94
  25. package/lib/locales/type.d.ts +3 -3
  26. package/lib/logger/index.js +4 -2
  27. package/lib/models/index.d.ts +4 -4
  28. package/lib/pubsub/index.d.ts +1 -1
  29. package/lib/pubsub/index.js +1 -3
  30. package/lib/request/cache.d.ts +1 -1
  31. package/lib/request/pisell2Request.d.ts +1 -1
  32. package/lib/routes/index.d.ts +2 -2
  33. package/lib/routes/index.js +3 -1
  34. package/lib/socket/components/SocketMonitorPage.js +6 -12
  35. package/lib/socket/heartbeat.js +10 -5
  36. package/lib/socket/index.js +1 -3
  37. package/lib/socket/monitor.js +26 -24
  38. package/lib/socket/reconnect.js +10 -3
  39. package/lib/socket/socket.js +12 -10
  40. package/lib/socket/types.d.ts +1 -1
  41. package/lib/storage/index.js +25 -24
  42. package/lib/tasks/index.js +333 -329
  43. package/lib/tasks/type.d.ts +4 -4
  44. package/lib/variables/index.d.ts +3 -3
  45. package/package.json +1 -1
  46. package/es/app/app.d.ts +0 -99
  47. package/es/applicationManager/application.d.ts +0 -197
  48. package/es/applicationManager/index.d.ts +0 -19
  49. package/es/index.d.ts +0 -7
  50. package/es/logger/index.d.ts +0 -135
  51. package/es/menuManager/index.d.ts +0 -28
  52. package/es/request/config.d.ts +0 -3
  53. package/es/request/index.d.ts +0 -24
  54. package/es/request/type.d.ts +0 -57
  55. package/es/tasks/index.d.ts +0 -127
  56. package/es/utils/adaptiveThrottle/index.d.ts +0 -36
  57. package/lib/app/app.d.ts +0 -99
  58. package/lib/applicationManager/application.d.ts +0 -197
  59. package/lib/applicationManager/index.d.ts +0 -19
  60. package/lib/index.d.ts +0 -7
  61. package/lib/logger/index.d.ts +0 -135
  62. package/lib/menuManager/index.d.ts +0 -28
  63. package/lib/request/config.d.ts +0 -3
  64. package/lib/request/index.d.ts +0 -24
  65. package/lib/request/type.d.ts +0 -57
  66. package/lib/tasks/index.d.ts +0 -127
  67. package/lib/utils/adaptiveThrottle/index.d.ts +0 -36
package/es/app/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import App, { AppOptions } from "./app";
3
- type AppContextType = {
3
+ declare type AppContextType = {
4
4
  globalData: any;
5
5
  setGlobalData: React.Dispatch<React.SetStateAction<any>>;
6
6
  app: App;
package/es/cmd/const.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export declare enum CMDCoreEnum {
2
- CMD_CONNECT = "cmd.connect",
3
- CMD_DISCONNECT = "cmd.disconnect",
4
- CMD_RECONNECT = "cmd.reconnect",
5
- CMD_MESSAGE = "cmd.message",
6
- CMD_ERROR = "cmd.error"
2
+ CMD_CONNECT,
3
+ CMD_DISCONNECT,
4
+ CMD_RECONNECT,
5
+ CMD_MESSAGE,
6
+ CMD_ERROR
7
7
  }
8
8
  declare const _default: {
9
9
  CMDCoreEnum: typeof CMDCoreEnum;
@@ -1,6 +1,6 @@
1
1
  import { ModelsState } from "../../models";
2
2
  declare const useStore: <T extends "global", D extends keyof ModelsState[T]>(props: {
3
3
  models: T;
4
- key?: D;
4
+ key?: D | undefined;
5
5
  }) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
6
6
  export default useStore;
@@ -326,17 +326,15 @@ var IndexDBManager = /*#__PURE__*/function () {
326
326
  case 10:
327
327
  _context3.prev = 10;
328
328
  _context3.t0 = _context3["catch"](3);
329
- if (log) {
330
- _this4.app.logger.addLog({
331
- type: 'error',
332
- title: uuid,
333
- metadata: {
334
- msg: '添加数据失败',
335
- error: _context3.t0.message
336
- }
337
- });
338
- }
339
- throw new Error('添加数据失败');
329
+ _this4.app.logger.addLog({
330
+ type: 'error',
331
+ title: uuid,
332
+ metadata: {
333
+ msg: '添加数据失败',
334
+ error: _context3.t0.message
335
+ }
336
+ });
337
+ throw new Error(_context3.t0 === null || _context3.t0 === void 0 ? void 0 : _context3.t0.message);
340
338
  case 14:
341
339
  case "end":
342
340
  return _context3.stop();
@@ -611,17 +609,15 @@ var IndexDBManager = /*#__PURE__*/function () {
611
609
  case 10:
612
610
  _context9.prev = 10;
613
611
  _context9.t0 = _context9["catch"](3);
614
- if (log) {
615
- _this7.app.logger.addLog({
616
- type: 'error',
617
- title: uuid,
618
- metadata: {
619
- msg: '数据更新失败',
620
- error: _context9.t0.message
621
- }
622
- });
623
- }
624
- throw new Error('更新数据失败');
612
+ _this7.app.logger.addLog({
613
+ type: 'error',
614
+ title: uuid,
615
+ metadata: {
616
+ msg: '数据更新失败',
617
+ error: _context9.t0.message
618
+ }
619
+ });
620
+ throw new Error(_context9.t0 === null || _context9.t0 === void 0 ? void 0 : _context9.t0.message);
625
621
  case 14:
626
622
  case "end":
627
623
  return _context9.stop();
@@ -1110,8 +1106,16 @@ var IndexDBManager = /*#__PURE__*/function () {
1110
1106
  case 9:
1111
1107
  _context23.prev = 9;
1112
1108
  _context23.t0 = _context23["catch"](2);
1113
- throw new Error('获取所有数据失败');
1114
- case 12:
1109
+ _this14.app.logger.addLog({
1110
+ type: 'error',
1111
+ title: "[ IndexDB ] ERROR: - getAll(".concat(storeName, ")"),
1112
+ metadata: {
1113
+ msg: '获取所有数据失败',
1114
+ error: _context23.t0.message
1115
+ }
1116
+ });
1117
+ throw new Error(_context23.t0 === null || _context23.t0 === void 0 ? void 0 : _context23.t0.message);
1118
+ case 13:
1115
1119
  case "end":
1116
1120
  return _context23.stop();
1117
1121
  }
@@ -1,5 +1,5 @@
1
- export type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
- export type MultiLanguage = {
1
+ export declare type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
+ export declare type MultiLanguage = {
3
3
  [key in Locale]: string;
4
4
  };
5
5
  export interface LibraryItem {
@@ -16,4 +16,4 @@ export interface LocaleConfig {
16
16
  [key in Locale]: LibraryItem;
17
17
  };
18
18
  }
19
- export type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
19
+ export declare type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
@@ -325,8 +325,9 @@ var LoggerManager = /*#__PURE__*/function () {
325
325
 
326
326
  // 将buffer中的metadata转换为对象
327
327
  buffer = (_this$logBuffer = this.logBuffer) === null || _this$logBuffer === void 0 ? void 0 : _this$logBuffer.map(function (item) {
328
- item.metadata = JSON.parse(item.metadata || "{}");
329
- return item;
328
+ return _objectSpread(_objectSpread({}, item || {}), {}, {
329
+ metadata: JSON.parse(item.metadata || "{}")
330
+ });
330
331
  });
331
332
  bufferIds = buffer.map(function (item) {
332
333
  return item.logId;
@@ -1,7 +1,7 @@
1
1
  import hooks from '../hooks';
2
2
  import { Provider as StoreProvider } from "react-redux";
3
3
  declare const models: import("./global").GlobalModal[];
4
- type ModalsType = (typeof models[number]);
4
+ declare type ModalsType = (typeof models[number]);
5
5
  export interface Store {
6
6
  getDataByModel: typeof getDataByModel;
7
7
  useStore: typeof hooks.useStore;
@@ -10,8 +10,8 @@ export interface Store {
10
10
  dispatch: any;
11
11
  getState: any;
12
12
  }
13
- export type ModelsNames = ModalsType['namespace'];
14
- export type ModelsState = {
13
+ export declare type ModelsNames = ModalsType['namespace'];
14
+ export declare type ModelsState = {
15
15
  [K in (ModalsType['namespace'])]: Extract<ModalsType, {
16
16
  namespace: K;
17
17
  }>['state'];
@@ -25,7 +25,7 @@ export type ModelsState = {
25
25
  * @Author: zhiwei.Wang
26
26
  * @Date: 2024-09-03 11:07
27
27
  */
28
- declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key?: D) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
28
+ declare const getDataByModel: <T extends "global", D extends keyof ModelsState[T]>(model: string, key?: D | undefined) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
29
29
  /**
30
30
  * @title: 设置数据到store
31
31
  * @description:
@@ -2,7 +2,7 @@
2
2
  * 发布订阅模块
3
3
  * 用于组件/服务间的事件通信
4
4
  */
5
- type EventCallback = (...args: any[]) => void;
5
+ declare type EventCallback = (...args: any[]) => void;
6
6
  interface EventSubscription {
7
7
  unsubscribe: () => void;
8
8
  }
@@ -1,5 +1,5 @@
1
1
  import { CacheProps } from './type';
2
- export type CacheType = 'memory' | 'storage' | 'indexDB';
2
+ export declare type CacheType = 'memory' | 'storage' | 'indexDB';
3
3
  /**
4
4
  * @title: 设置缓存
5
5
  * @description:
@@ -1,4 +1,4 @@
1
- type RequestMethod = any;
1
+ declare type RequestMethod = any;
2
2
  declare const pisell2Get: RequestMethod;
3
3
  declare const pisell2Post: RequestMethod;
4
4
  declare const pisell2Put: RequestMethod;
@@ -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 | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
23
+ renderComponent(item: RouteType, children?: React.ReactNode): string | number | boolean | JSX.Element | React.ReactFragment | null | undefined;
24
24
  getPageByRoute(route: string): ApplicationInterface | undefined;
25
25
  getRouterComponent({ fallback }: {
26
26
  fallback?: React.ReactNode;
27
- }): React.JSX.Element[];
27
+ }): JSX.Element[];
28
28
  }
@@ -76,7 +76,7 @@ export interface ReconnectOptions {
76
76
  /**
77
77
  * 事件处理函数类型
78
78
  */
79
- export type EventHandler = (...args: any[]) => void;
79
+ export declare type EventHandler = (...args: any[]) => void;
80
80
  /**
81
81
  * 事件处理函数映射
82
82
  */
@@ -1,4 +1,4 @@
1
- export type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
1
+ export declare type TaskRunStatus = "pending" | "in-progress" | "success" | "failure";
2
2
  export interface Task {
3
3
  id?: string;
4
4
  type?: "local" | "cloud";
@@ -37,9 +37,9 @@ export interface Task {
37
37
  export interface TaskConfig {
38
38
  tasks: Task[];
39
39
  }
40
- type TaskModuleName = string;
41
- type TaskQueueName = string;
42
- type TaskStatus = "uncompleted" | "completed";
40
+ declare type TaskModuleName = string;
41
+ declare type TaskQueueName = string;
42
+ declare type TaskStatus = "uncompleted" | "completed";
43
43
  export interface TaskQueue {
44
44
  status: TaskStatus;
45
45
  tasks: Task[];
@@ -1,6 +1,6 @@
1
- export type VariableMap = Record<string, string>;
1
+ export declare type VariableMap = Record<string, string>;
2
2
  declare const _default: {
3
- setConfig: (newConfig: Partial<import("@").VariablesConfig>) => void;
4
- getConfig: () => import("@").VariablesConfig;
3
+ setConfig: (newConfig: Partial<import("./type").VariablesConfig>) => void;
4
+ getConfig: () => import("./type").VariablesConfig;
5
5
  };
6
6
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import App, { AppOptions } from "./app";
3
- type AppContextType = {
3
+ declare type AppContextType = {
4
4
  globalData: any;
5
5
  setGlobalData: React.Dispatch<React.SetStateAction<any>>;
6
6
  app: App;
package/lib/aws/index.js CHANGED
@@ -32,6 +32,9 @@ var defaultUploadParams = {
32
32
  // 设置ACL权限为公共读取
33
33
  };
34
34
  var AWS = class {
35
+ s3Client;
36
+ app;
37
+ config;
35
38
  constructor(app, options) {
36
39
  this.app = app;
37
40
  if (options) {
@@ -1,9 +1,9 @@
1
1
  export declare enum CMDCoreEnum {
2
- CMD_CONNECT = "cmd.connect",
3
- CMD_DISCONNECT = "cmd.disconnect",
4
- CMD_RECONNECT = "cmd.reconnect",
5
- CMD_MESSAGE = "cmd.message",
6
- CMD_ERROR = "cmd.error"
2
+ CMD_CONNECT,
3
+ CMD_DISCONNECT,
4
+ CMD_RECONNECT,
5
+ CMD_MESSAGE,
6
+ CMD_ERROR
7
7
  }
8
8
  declare const _default: {
9
9
  CMDCoreEnum: typeof CMDCoreEnum;
package/lib/cmd/const.js CHANGED
@@ -25,11 +25,11 @@ __export(const_exports, {
25
25
  module.exports = __toCommonJS(const_exports);
26
26
  var prefix = "cmd";
27
27
  var CMDCoreEnum = ((CMDCoreEnum2) => {
28
- CMDCoreEnum2[CMDCoreEnum2["CMD_CONNECT"] = `${prefix}.connect`] = "CMD_CONNECT";
29
- CMDCoreEnum2[CMDCoreEnum2["CMD_DISCONNECT"] = `${prefix}.disconnect`] = "CMD_DISCONNECT";
30
- CMDCoreEnum2[CMDCoreEnum2["CMD_RECONNECT"] = `${prefix}.reconnect`] = "CMD_RECONNECT";
31
- CMDCoreEnum2[CMDCoreEnum2["CMD_MESSAGE"] = `${prefix}.message`] = "CMD_MESSAGE";
32
- CMDCoreEnum2[CMDCoreEnum2["CMD_ERROR"] = `${prefix}.error`] = "CMD_ERROR";
28
+ CMDCoreEnum2["CMD_CONNECT"] = `${prefix}.connect`;
29
+ CMDCoreEnum2["CMD_DISCONNECT"] = `${prefix}.disconnect`;
30
+ CMDCoreEnum2["CMD_RECONNECT"] = `${prefix}.reconnect`;
31
+ CMDCoreEnum2["CMD_MESSAGE"] = `${prefix}.message`;
32
+ CMDCoreEnum2["CMD_ERROR"] = `${prefix}.error`;
33
33
  return CMDCoreEnum2;
34
34
  })(CMDCoreEnum || {});
35
35
  var const_default = { CMDCoreEnum };
package/lib/cmd/index.js CHANGED
@@ -36,6 +36,8 @@ module.exports = __toCommonJS(cmd_exports);
36
36
  var import_socket = __toESM(require("../socket"));
37
37
  var import_const = require("./const");
38
38
  var CMD = class {
39
+ app;
40
+ options;
39
41
  constructor(app, options) {
40
42
  this.app = app;
41
43
  this.options = options;
@@ -35,10 +35,8 @@ function getCookie(name) {
35
35
  const ca = document.cookie.split(";");
36
36
  for (let i = 0; i < ca.length; i++) {
37
37
  let c = ca[i];
38
- while (c.charAt(0) === " ")
39
- c = c.substring(1, c.length);
40
- if (c.indexOf(nameEQ) === 0)
41
- return c.substring(nameEQ.length, c.length);
38
+ while (c.charAt(0) === " ") c = c.substring(1, c.length);
39
+ if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
42
40
  }
43
41
  return null;
44
42
  }
package/lib/data/index.js CHANGED
@@ -23,6 +23,9 @@ __export(data_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(data_exports);
25
25
  var Data = class {
26
+ app;
27
+ storage;
28
+ store;
26
29
  constructor(app) {
27
30
  this.app = app;
28
31
  this.storage = app.storage;
@@ -1,6 +1,6 @@
1
1
  import { ModelsState } from "../../models";
2
2
  declare const useStore: <T extends "global", D extends keyof ModelsState[T]>(props: {
3
3
  models: T;
4
- key?: D;
4
+ key?: D | undefined;
5
5
  }) => D extends undefined ? ModelsState[T] : ModelsState[T][D];
6
6
  export default useStore;
@@ -220,14 +220,12 @@ var IndexDBManager = class _IndexDBManager {
220
220
  }
221
221
  return data;
222
222
  } catch (error) {
223
- if (log) {
224
- this.app.logger.addLog({
225
- type: "error",
226
- title: uuid,
227
- metadata: { msg: "添加数据失败", error: error.message }
228
- });
229
- }
230
- throw new Error("添加数据失败");
223
+ this.app.logger.addLog({
224
+ type: "error",
225
+ title: uuid,
226
+ metadata: { msg: "添加数据失败", error: error.message }
227
+ });
228
+ throw new Error(error == null ? void 0 : error.message);
231
229
  }
232
230
  })(),
233
231
  `add(${storeName})`
@@ -344,14 +342,12 @@ var IndexDBManager = class _IndexDBManager {
344
342
  }
345
343
  return data;
346
344
  } catch (error) {
347
- if (log) {
348
- this.app.logger.addLog({
349
- type: "error",
350
- title: uuid,
351
- metadata: { msg: "数据更新失败", error: error.message }
352
- });
353
- }
354
- throw new Error("更新数据失败");
345
+ this.app.logger.addLog({
346
+ type: "error",
347
+ title: uuid,
348
+ metadata: { msg: "数据更新失败", error: error.message }
349
+ });
350
+ throw new Error(error == null ? void 0 : error.message);
355
351
  }
356
352
  })(),
357
353
  `update(${storeName})`
@@ -550,7 +546,12 @@ var IndexDBManager = class _IndexDBManager {
550
546
  const results = await this.db.table(storeName).toArray();
551
547
  return results;
552
548
  } catch (error) {
553
- throw new Error("获取所有数据失败");
549
+ this.app.logger.addLog({
550
+ type: "error",
551
+ title: `[ IndexDB ] ERROR: - getAll(${storeName})`,
552
+ metadata: { msg: "获取所有数据失败", error: error.message }
553
+ });
554
+ throw new Error(error == null ? void 0 : error.message);
554
555
  }
555
556
  })(),
556
557
  `getAll(${storeName})`
@@ -39,101 +39,15 @@ var import_zh_CN = __toESM(require("./zh-CN"));
39
39
  var import_zh_HK = __toESM(require("./zh-HK"));
40
40
  var import_original = __toESM(require("./original"));
41
41
  var Locales = class {
42
+ app;
43
+ // 当前语言 本地语言 > 英文语言包
44
+ locale = import_en.default.locale;
45
+ // 语言包
46
+ library = [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
47
+ pre[cur.locale] = cur;
48
+ return pre;
49
+ }, {});
42
50
  constructor(app, options) {
43
- // 当前语言 本地语言 > 英文语言包
44
- this.locale = import_en.default.locale;
45
- // 语言包
46
- this.library = [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
47
- pre[cur.locale] = cur;
48
- return pre;
49
- }, {});
50
- this.getLocale = () => {
51
- return this.locale;
52
- };
53
- this.getCurrentTexts = (locale) => {
54
- return this.library[locale || this.locale].translations;
55
- };
56
- this.setLocale = (locale, reload = false) => {
57
- this.locale = locale;
58
- if (reload) {
59
- window.location.reload();
60
- return;
61
- }
62
- };
63
- this.getText = (id, locale) => {
64
- var _a;
65
- return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
66
- };
67
- this.isCN = () => {
68
- let locale = this.getLocale();
69
- return locale === "zh-CN" || locale === "zh-HK";
70
- };
71
- this.loadLibraryByUrl = async (urls) => {
72
- try {
73
- let fetchList = urls.map((item) => {
74
- if (typeof item === "string") {
75
- return fetch(item);
76
- }
77
- if (typeof item === "function") {
78
- return item();
79
- }
80
- if (typeof item === "object" && item !== null && "locale" in item) {
81
- return Promise.resolve(item);
82
- }
83
- return item;
84
- });
85
- let res = await Promise.all(fetchList);
86
- let library = { ...this.library };
87
- for (const item of res) {
88
- const _item = item instanceof Response ? await item.json() : item;
89
- library = {
90
- ...library,
91
- [_item.locale]: import_lodash.default.mergeWith(library[_item.locale] || {}, _item)
92
- };
93
- }
94
- this.library = library;
95
- return library;
96
- } catch (err) {
97
- console.log(err);
98
- throw err;
99
- }
100
- };
101
- this.loadLibrary = (urls) => {
102
- return this.loadLibraryByUrl(urls);
103
- };
104
- this.translation = (text, locale) => {
105
- if (!text) {
106
- return "";
107
- }
108
- if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
109
- return text;
110
- }
111
- let primary = locale || this.getLocale();
112
- if (typeof text === "string") {
113
- return text;
114
- }
115
- return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
116
- };
117
- this.getLibraryByData = (data) => {
118
- return data.reduce((pre, next) => {
119
- return {
120
- ...pre,
121
- [next.locale]: next
122
- };
123
- }, {});
124
- };
125
- this.createTextsByLibrary = (id, library) => {
126
- const _library = library || this.library;
127
- return Object.keys(_library).reduce((pre, next) => {
128
- var _a;
129
- let _pre = { ...pre };
130
- let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
131
- if (cur) {
132
- _pre[_library[next].locale] = cur;
133
- }
134
- return _pre;
135
- }, {});
136
- };
137
51
  this.app = app;
138
52
  this.locale = (options == null ? void 0 : options.locale) || this.app.storage.getStorage("locale") || import_en.default.locale;
139
53
  this.library = (options == null ? void 0 : options.library) || [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
@@ -141,6 +55,57 @@ var Locales = class {
141
55
  return pre;
142
56
  }, {});
143
57
  }
58
+ getLocale = () => {
59
+ return this.locale;
60
+ };
61
+ getCurrentTexts = (locale) => {
62
+ return this.library[locale || this.locale].translations;
63
+ };
64
+ setLocale = (locale, reload = false) => {
65
+ this.locale = locale;
66
+ if (reload) {
67
+ window.location.reload();
68
+ return;
69
+ }
70
+ };
71
+ getText = (id, locale) => {
72
+ var _a;
73
+ return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
74
+ };
75
+ isCN = () => {
76
+ let locale = this.getLocale();
77
+ return locale === "zh-CN" || locale === "zh-HK";
78
+ };
79
+ loadLibraryByUrl = async (urls) => {
80
+ try {
81
+ let fetchList = urls.map((item) => {
82
+ if (typeof item === "string") {
83
+ return fetch(item);
84
+ }
85
+ if (typeof item === "function") {
86
+ return item();
87
+ }
88
+ if (typeof item === "object" && item !== null && "locale" in item) {
89
+ return Promise.resolve(item);
90
+ }
91
+ return item;
92
+ });
93
+ let res = await Promise.all(fetchList);
94
+ let library = { ...this.library };
95
+ for (const item of res) {
96
+ const _item = item instanceof Response ? await item.json() : item;
97
+ library = {
98
+ ...library,
99
+ [_item.locale]: import_lodash.default.mergeWith(library[_item.locale] || {}, _item)
100
+ };
101
+ }
102
+ this.library = library;
103
+ return library;
104
+ } catch (err) {
105
+ console.log(err);
106
+ throw err;
107
+ }
108
+ };
144
109
  loadLibraryByItems(libraryList) {
145
110
  let library = { ...this.library };
146
111
  libraryList.forEach((item) => {
@@ -151,6 +116,42 @@ var Locales = class {
151
116
  });
152
117
  this.library = library;
153
118
  }
119
+ loadLibrary = (urls) => {
120
+ return this.loadLibraryByUrl(urls);
121
+ };
122
+ translation = (text, locale) => {
123
+ if (!text) {
124
+ return "";
125
+ }
126
+ if ((0, import_utils.isString)(text) || (0, import_utils.isNumber)(text)) {
127
+ return text;
128
+ }
129
+ let primary = locale || this.getLocale();
130
+ if (typeof text === "string") {
131
+ return text;
132
+ }
133
+ return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
134
+ };
135
+ getLibraryByData = (data) => {
136
+ return data.reduce((pre, next) => {
137
+ return {
138
+ ...pre,
139
+ [next.locale]: next
140
+ };
141
+ }, {});
142
+ };
143
+ createTextsByLibrary = (id, library) => {
144
+ const _library = library || this.library;
145
+ return Object.keys(_library).reduce((pre, next) => {
146
+ var _a;
147
+ let _pre = { ...pre };
148
+ let cur = (_a = _library[next].translations) == null ? void 0 : _a[id];
149
+ if (cur) {
150
+ _pre[_library[next].locale] = cur;
151
+ }
152
+ return _pre;
153
+ }, {});
154
+ };
154
155
  };
155
156
  // Annotate the CommonJS export names for ESM import in node:
156
157
  0 && (module.exports = {
@@ -1,5 +1,5 @@
1
- export type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
- export type MultiLanguage = {
1
+ export declare type Locale = 'original' | 'en' | 'zh-CN' | 'zh-HK' | string;
2
+ export declare type MultiLanguage = {
3
3
  [key in Locale]: string;
4
4
  };
5
5
  export interface LibraryItem {
@@ -16,4 +16,4 @@ export interface LocaleConfig {
16
16
  [key in Locale]: LibraryItem;
17
17
  };
18
18
  }
19
- export type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
19
+ export declare type LoadLibraryByUrlParams = (string | Promise<LibraryItem> | (() => Promise<LibraryItem>) | LibraryItem)[];
@@ -219,8 +219,10 @@ var LoggerManager = class {
219
219
  const fileName = await this.createAWSFileName(urgent);
220
220
  console.log("-------- 存储日志到AWS 开始", fileName);
221
221
  const buffer = (_a = this.logBuffer) == null ? void 0 : _a.map((item) => {
222
- item.metadata = JSON.parse(item.metadata || "{}");
223
- return item;
222
+ return {
223
+ ...item || {},
224
+ metadata: JSON.parse(item.metadata || "{}")
225
+ };
224
226
  });
225
227
  const bufferIds = buffer.map((item) => item.logId);
226
228
  const logs = JSON.stringify(buffer, null, 2);