@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.
- package/es/app/index.d.ts +1 -1
- package/es/cmd/const.d.ts +5 -5
- package/es/hooks/useStore/index.d.ts +1 -1
- package/es/indexDB/index.js +28 -24
- package/es/locales/type.d.ts +3 -3
- package/es/logger/index.js +3 -2
- package/es/models/index.d.ts +4 -4
- package/es/pubsub/index.d.ts +1 -1
- package/es/request/cache.d.ts +1 -1
- package/es/request/pisell2Request.d.ts +1 -1
- package/es/routes/index.d.ts +2 -2
- package/es/socket/types.d.ts +1 -1
- package/es/tasks/type.d.ts +4 -4
- package/es/variables/index.d.ts +3 -3
- package/lib/app/index.d.ts +1 -1
- package/lib/aws/index.js +3 -0
- package/lib/cmd/const.d.ts +5 -5
- package/lib/cmd/const.js +5 -5
- package/lib/cmd/index.js +2 -0
- package/lib/cookie/index.js +2 -4
- package/lib/data/index.js +3 -0
- package/lib/hooks/useStore/index.d.ts +1 -1
- package/lib/indexDB/index.js +18 -17
- package/lib/locales/index.js +95 -94
- package/lib/locales/type.d.ts +3 -3
- package/lib/logger/index.js +4 -2
- package/lib/models/index.d.ts +4 -4
- package/lib/pubsub/index.d.ts +1 -1
- package/lib/pubsub/index.js +1 -3
- package/lib/request/cache.d.ts +1 -1
- package/lib/request/pisell2Request.d.ts +1 -1
- package/lib/routes/index.d.ts +2 -2
- package/lib/routes/index.js +3 -1
- package/lib/socket/components/SocketMonitorPage.js +6 -12
- package/lib/socket/heartbeat.js +10 -5
- package/lib/socket/index.js +1 -3
- package/lib/socket/monitor.js +26 -24
- package/lib/socket/reconnect.js +10 -3
- package/lib/socket/socket.js +12 -10
- package/lib/socket/types.d.ts +1 -1
- package/lib/storage/index.js +25 -24
- package/lib/tasks/index.js +333 -329
- package/lib/tasks/type.d.ts +4 -4
- package/lib/variables/index.d.ts +3 -3
- package/package.json +1 -1
- package/es/app/app.d.ts +0 -99
- package/es/applicationManager/application.d.ts +0 -197
- package/es/applicationManager/index.d.ts +0 -19
- package/es/index.d.ts +0 -7
- package/es/logger/index.d.ts +0 -135
- package/es/menuManager/index.d.ts +0 -28
- package/es/request/config.d.ts +0 -3
- package/es/request/index.d.ts +0 -24
- package/es/request/type.d.ts +0 -57
- package/es/tasks/index.d.ts +0 -127
- package/es/utils/adaptiveThrottle/index.d.ts +0 -36
- package/lib/app/app.d.ts +0 -99
- package/lib/applicationManager/application.d.ts +0 -197
- package/lib/applicationManager/index.d.ts +0 -19
- package/lib/index.d.ts +0 -7
- package/lib/logger/index.d.ts +0 -135
- package/lib/menuManager/index.d.ts +0 -28
- package/lib/request/config.d.ts +0 -3
- package/lib/request/index.d.ts +0 -24
- package/lib/request/type.d.ts +0 -57
- package/lib/tasks/index.d.ts +0 -127
- package/lib/utils/adaptiveThrottle/index.d.ts +0 -36
package/es/app/index.d.ts
CHANGED
package/es/cmd/const.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare enum CMDCoreEnum {
|
|
2
|
-
CMD_CONNECT
|
|
3
|
-
CMD_DISCONNECT
|
|
4
|
-
CMD_RECONNECT
|
|
5
|
-
CMD_MESSAGE
|
|
6
|
-
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;
|
package/es/indexDB/index.js
CHANGED
|
@@ -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
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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
|
-
|
|
1114
|
-
|
|
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
|
}
|
package/es/locales/type.d.ts
CHANGED
|
@@ -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)[];
|
package/es/logger/index.js
CHANGED
|
@@ -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
|
-
|
|
329
|
-
|
|
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;
|
package/es/models/index.d.ts
CHANGED
|
@@ -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:
|
package/es/pubsub/index.d.ts
CHANGED
package/es/request/cache.d.ts
CHANGED
package/es/routes/index.d.ts
CHANGED
|
@@ -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 |
|
|
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
|
-
}):
|
|
27
|
+
}): JSX.Element[];
|
|
28
28
|
}
|
package/es/socket/types.d.ts
CHANGED
package/es/tasks/type.d.ts
CHANGED
|
@@ -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[];
|
package/es/variables/index.d.ts
CHANGED
|
@@ -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("
|
|
4
|
-
getConfig: () => import("
|
|
3
|
+
setConfig: (newConfig: Partial<import("./type").VariablesConfig>) => void;
|
|
4
|
+
getConfig: () => import("./type").VariablesConfig;
|
|
5
5
|
};
|
|
6
6
|
export default _default;
|
package/lib/app/index.d.ts
CHANGED
package/lib/aws/index.js
CHANGED
package/lib/cmd/const.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare enum CMDCoreEnum {
|
|
2
|
-
CMD_CONNECT
|
|
3
|
-
CMD_DISCONNECT
|
|
4
|
-
CMD_RECONNECT
|
|
5
|
-
CMD_MESSAGE
|
|
6
|
-
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[
|
|
29
|
-
CMDCoreEnum2[
|
|
30
|
-
CMDCoreEnum2[
|
|
31
|
-
CMDCoreEnum2[
|
|
32
|
-
CMDCoreEnum2[
|
|
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
package/lib/cookie/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
@@ -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;
|
package/lib/indexDB/index.js
CHANGED
|
@@ -220,14 +220,12 @@ var IndexDBManager = class _IndexDBManager {
|
|
|
220
220
|
}
|
|
221
221
|
return data;
|
|
222
222
|
} catch (error) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
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})`
|
package/lib/locales/index.js
CHANGED
|
@@ -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 = {
|
package/lib/locales/type.d.ts
CHANGED
|
@@ -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)[];
|
package/lib/logger/index.js
CHANGED
|
@@ -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
|
-
|
|
223
|
-
|
|
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);
|