@pisell/core 1.0.60 → 1.0.62

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.
@@ -338,6 +338,84 @@ var IndexDBManager = class _IndexDBManager {
338
338
  this.debouncedUpdateFlushing.delete(storeName);
339
339
  }
340
340
  }
341
+ /**
342
+ * 批量添加数据到指定的存储对象
343
+ * @param {string} storeName - 存储对象名称
344
+ * @param {T[]} dataList - 要批量添加的数据数组
345
+ * @param {boolean} [log=false] - 是否记录日志
346
+ * @returns {Promise<T[]>} 成功添加的数据数组
347
+ * @template T
348
+ */
349
+ async bulkAdd(storeName, dataList, log = false) {
350
+ if (!dataList || dataList.length === 0) {
351
+ return [];
352
+ }
353
+ if (!this.useIndexDB) {
354
+ const storeConfig = this.stores.find((s) => s.name === storeName);
355
+ const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
356
+ const memStore = this.getMemoryStore(storeName);
357
+ dataList.forEach((data) => {
358
+ const key = data[keyPath];
359
+ memStore.set(key, data);
360
+ });
361
+ return dataList;
362
+ }
363
+ const uuid = `[ IndexDB ] BULK_ADD: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
364
+ if (log) {
365
+ this.app.logger.addLog({
366
+ type: "info",
367
+ title: uuid,
368
+ metadata: {
369
+ msg: "批量添加数据前",
370
+ count: dataList.length
371
+ }
372
+ });
373
+ }
374
+ return this.withTimeout(
375
+ (async () => {
376
+ if (!this.db) {
377
+ if (log) {
378
+ this.app.logger.addLog({
379
+ type: "error",
380
+ title: uuid,
381
+ metadata: {
382
+ msg: "批量添加数据前 数据库未连接",
383
+ count: dataList.length
384
+ }
385
+ });
386
+ }
387
+ throw new Error("数据库未连接");
388
+ }
389
+ try {
390
+ await this.db.table(storeName).bulkAdd(dataList);
391
+ if (log) {
392
+ this.app.logger.addLog({
393
+ type: "info",
394
+ title: uuid,
395
+ metadata: {
396
+ msg: "批量添加成功",
397
+ count: dataList.length
398
+ }
399
+ });
400
+ }
401
+ return dataList;
402
+ } catch (error) {
403
+ const hasExistingData = ((error == null ? void 0 : error.message) || "").includes("exists") || ((error == null ? void 0 : error.message) || "").includes("Key already exists");
404
+ this.app.logger.addLog({
405
+ type: hasExistingData ? "info" : "error",
406
+ title: uuid,
407
+ metadata: {
408
+ msg: "批量添加数据失败",
409
+ count: dataList.length,
410
+ error: error.message
411
+ }
412
+ });
413
+ throw new Error(error == null ? void 0 : error.message);
414
+ }
415
+ })(),
416
+ `bulkAdd(${storeName})`
417
+ );
418
+ }
341
419
  /**
342
420
  * 添加数据到指定的存储对象
343
421
  * @param {string} storeName - 存储对象名称
@@ -463,6 +541,83 @@ var IndexDBManager = class _IndexDBManager {
463
541
  `get(${storeName})`
464
542
  );
465
543
  }
544
+ /**
545
+ * 批量更新指定存储对象中的数据
546
+ * @param {string} storeName - 存储对象名称
547
+ * @param {T[]} dataList - 要批量更新的数据数组
548
+ * @param {boolean} [log=false] - 是否记录日志
549
+ * @returns {Promise<T[]>} 更新后的数据数组
550
+ * @template T
551
+ */
552
+ async bulkUpdate(storeName, dataList, log = false) {
553
+ if (!dataList || dataList.length === 0) {
554
+ return [];
555
+ }
556
+ if (!this.useIndexDB) {
557
+ const storeConfig = this.stores.find((s) => s.name === storeName);
558
+ const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
559
+ const memStore = this.getMemoryStore(storeName);
560
+ dataList.forEach((data) => {
561
+ const key = data[keyPath];
562
+ memStore.set(key, data);
563
+ });
564
+ return dataList;
565
+ }
566
+ const uuid = `[ IndexDB ] BULK_UPDATE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
567
+ if (log) {
568
+ this.app.logger.addLog({
569
+ type: "info",
570
+ title: uuid,
571
+ metadata: {
572
+ msg: "批量更新数据前",
573
+ count: dataList.length
574
+ }
575
+ });
576
+ }
577
+ return this.withTimeout(
578
+ (async () => {
579
+ if (!this.db) {
580
+ if (log) {
581
+ this.app.logger.addLog({
582
+ type: "error",
583
+ title: uuid,
584
+ metadata: {
585
+ msg: "批量更新数据前 数据库未连接",
586
+ count: dataList.length
587
+ }
588
+ });
589
+ }
590
+ throw new Error("数据库未连接");
591
+ }
592
+ try {
593
+ await this.db.table(storeName).bulkPut(dataList);
594
+ if (log) {
595
+ this.app.logger.addLog({
596
+ type: "info",
597
+ title: uuid,
598
+ metadata: {
599
+ msg: "批量更新成功",
600
+ count: dataList.length
601
+ }
602
+ });
603
+ }
604
+ return dataList;
605
+ } catch (error) {
606
+ this.app.logger.addLog({
607
+ type: "error",
608
+ title: uuid,
609
+ metadata: {
610
+ msg: "批量更新数据失败",
611
+ count: dataList.length,
612
+ error: error.message
613
+ }
614
+ });
615
+ throw new Error(error == null ? void 0 : error.message);
616
+ }
617
+ })(),
618
+ `bulkUpdate(${storeName})`
619
+ );
620
+ }
466
621
  /**
467
622
  * 更新指定存储对象中的数据
468
623
  * @param {string} storeName - 存储对象名称
@@ -512,6 +667,77 @@ var IndexDBManager = class _IndexDBManager {
512
667
  `update(${storeName})`
513
668
  );
514
669
  }
670
+ /**
671
+ * 批量删除指定存储对象中的数据
672
+ * @param {string} storeName - 存储对象名称
673
+ * @param {(string|number)[]} keys - 数据主键数组
674
+ * @param {boolean} [log=false] - 是否记录日志
675
+ * @returns {Promise<boolean>} 删除是否成功
676
+ */
677
+ async bulkDelete(storeName, keys, log = false) {
678
+ if (!keys || keys.length === 0) {
679
+ return true;
680
+ }
681
+ if (!this.useIndexDB) {
682
+ const memStore = this.getMemoryStore(storeName);
683
+ keys.forEach((key) => memStore.delete(key));
684
+ return true;
685
+ }
686
+ const uuid = `[ IndexDB ] BULK_DELETE: - ${storeName} - ${(0, import_dayjs.default)().valueOf()}`;
687
+ if (log) {
688
+ this.app.logger.addLog({
689
+ type: "info",
690
+ title: uuid,
691
+ metadata: {
692
+ msg: "批量删除数据前",
693
+ count: keys.length
694
+ }
695
+ });
696
+ }
697
+ return this.withTimeout(
698
+ (async () => {
699
+ if (!this.db) {
700
+ if (log) {
701
+ this.app.logger.addLog({
702
+ type: "error",
703
+ title: uuid,
704
+ metadata: {
705
+ msg: "批量删除数据前 数据库未连接",
706
+ count: keys.length
707
+ }
708
+ });
709
+ }
710
+ throw new Error("数据库未连接");
711
+ }
712
+ try {
713
+ await this.db.table(storeName).bulkDelete(keys);
714
+ if (log) {
715
+ this.app.logger.addLog({
716
+ type: "info",
717
+ title: uuid,
718
+ metadata: {
719
+ msg: "批量删除成功",
720
+ count: keys.length
721
+ }
722
+ });
723
+ }
724
+ return true;
725
+ } catch (error) {
726
+ this.app.logger.addLog({
727
+ type: "error",
728
+ title: uuid,
729
+ metadata: {
730
+ msg: "批量删除数据失败",
731
+ count: keys.length,
732
+ error: error.message
733
+ }
734
+ });
735
+ throw new Error(error == null ? void 0 : error.message);
736
+ }
737
+ })(),
738
+ `bulkDelete(${storeName})`
739
+ );
740
+ }
515
741
  /**
516
742
  * 删除指定存储对象中的数据
517
743
  * @param {string} storeName - 存储对象名称
@@ -37,20 +37,22 @@ var import_utils = require("@pisell/utils");
37
37
  var import_en = __toESM(require("./en"));
38
38
  var import_zh_CN = __toESM(require("./zh-CN"));
39
39
  var import_zh_HK = __toESM(require("./zh-HK"));
40
+ var import_ja = __toESM(require("./ja"));
41
+ var import_pt = __toESM(require("./pt"));
40
42
  var import_original = __toESM(require("./original"));
41
43
  var Locales = class {
42
44
  app;
43
45
  // 当前语言 本地语言 > 英文语言包
44
46
  locale = import_en.default.locale;
45
47
  // 语言包
46
- library = [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default].reduce((pre, cur) => {
48
+ library = [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default, import_ja.default, import_pt.default].reduce((pre, cur) => {
47
49
  pre[cur.locale] = cur;
48
50
  return pre;
49
51
  }, {});
50
52
  constructor(app, options) {
51
53
  this.app = app;
52
54
  this.locale = (options == null ? void 0 : options.locale) || this.app.storage.getStorage("locale") || import_en.default.locale;
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) => {
55
+ this.library = (options == null ? void 0 : options.library) || [import_original.default, import_en.default, import_zh_CN.default, import_zh_HK.default, import_ja.default, import_pt.default].reduce((pre, cur) => {
54
56
  pre[cur.locale] = cur;
55
57
  return pre;
56
58
  }, {});
@@ -69,8 +71,8 @@ var Locales = class {
69
71
  }
70
72
  };
71
73
  getText = (id, locale) => {
72
- var _a;
73
- return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || id;
74
+ var _a, _b;
75
+ return ((_a = this.getCurrentTexts(locale)) == null ? void 0 : _a[id]) || ((_b = this.getCurrentTexts("en")) == null ? void 0 : _b[id]) || id;
74
76
  };
75
77
  isCN = () => {
76
78
  let locale = this.getLocale();
@@ -130,7 +132,7 @@ var Locales = class {
130
132
  if (typeof text === "string") {
131
133
  return text;
132
134
  }
133
- return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"];
135
+ return text[primary] || text["original"] || text["en"] || text["zh-CN"] || text["zh-HK"] || text["ja"] || text["pt"];
134
136
  };
135
137
  getLibraryByData = (data) => {
136
138
  return data.reduce((pre, next) => {
@@ -0,0 +1,3 @@
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
3
+ export default _default;
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/locales/ja.ts
20
+ var ja_exports = {};
21
+ __export(ja_exports, {
22
+ default: () => ja_default
23
+ });
24
+ module.exports = __toCommonJS(ja_exports);
25
+ var ja_default = {
26
+ "locale": "ja",
27
+ "name": "japanese",
28
+ "translations": {}
29
+ };
@@ -0,0 +1,3 @@
1
+ import { LibraryItem } from './type';
2
+ declare const _default: LibraryItem;
3
+ export default _default;
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/locales/pt.ts
20
+ var pt_exports = {};
21
+ __export(pt_exports, {
22
+ default: () => pt_default
23
+ });
24
+ module.exports = __toCommonJS(pt_exports);
25
+ var pt_default = {
26
+ "locale": "pt",
27
+ "name": "portuguese",
28
+ "translations": {}
29
+ };
@@ -0,0 +1,135 @@
1
+ import App from "../app";
2
+ export declare type LogConsoleType = "info" | "warning" | "error" | "debug";
3
+ /**
4
+ * 日志项接口
5
+ */
6
+ interface LogItem {
7
+ logId?: string | number;
8
+ type: LogConsoleType;
9
+ title: string;
10
+ date?: string;
11
+ metadata?: any;
12
+ feishu?: any;
13
+ }
14
+ interface LogFile {
15
+ fileName: string;
16
+ date: string;
17
+ fileContent: LogFileContent;
18
+ }
19
+ interface LogFileContent {
20
+ metadata: any;
21
+ logs: LogItem[];
22
+ }
23
+ export interface LoggerOptions {
24
+ prefix?: string;
25
+ checkInterval?: number;
26
+ feishuConfig?: any;
27
+ retentionDays?: number;
28
+ }
29
+ /**
30
+ * 日志管理器类
31
+ */
32
+ declare class LoggerManager {
33
+ private logBuffer;
34
+ private timer;
35
+ private checkInterval;
36
+ private prefix;
37
+ private metadata;
38
+ private db;
39
+ private app;
40
+ private feishuConfig;
41
+ private retentionDays;
42
+ private metadataFunction;
43
+ private status;
44
+ /**
45
+ * 构造函数
46
+ * @param prefix 日志前缀
47
+ * @param checkInterval 检查间隔时间,默认5分钟
48
+ */
49
+ constructor(app: App, options?: LoggerOptions);
50
+ init(): Promise<void>;
51
+ /**
52
+ * 初始化 IndexDB
53
+ */
54
+ private initDB;
55
+ /**
56
+ * 设置元数据
57
+ * @param metadata 元数据
58
+ */
59
+ setMetadata(metadata: any): void;
60
+ setMetadataFunction(metadataFunction: () => any): void;
61
+ /**
62
+ * 初始化定时器
63
+ */
64
+ initTimer(): void;
65
+ private setStatus;
66
+ stop(): void;
67
+ /**
68
+ * 添加日志
69
+ * @param log 日志项
70
+ */
71
+ addLog(log: LogItem): void;
72
+ /**
73
+ * 发送飞书通知
74
+ * @param log 日志项
75
+ */
76
+ private sendFeishuNotification;
77
+ /**
78
+ * 创建日志文件名
79
+ * @returns 日志文件名
80
+ */
81
+ private createFileName;
82
+ /**
83
+ * 创建AWS日志文件名
84
+ * @param isManual 紧急上传
85
+ * @returns 日志文件名
86
+ */
87
+ createAWSFileName(urgent?: boolean): Promise<any>;
88
+ /**
89
+ * 创建日志文件
90
+ * @param _fileName 文件名
91
+ * @returns 日志文件对象
92
+ */
93
+ private createFile;
94
+ /**
95
+ * 存储日志到持久化存储
96
+ */
97
+ storeLog(urgent?: boolean): Promise<void>;
98
+ uploadIndexDBLog(): Promise<void>;
99
+ private storeLogToIndexDB;
100
+ /**
101
+ * 清理旧日志,只保留最近指定天数的日志
102
+ */
103
+ private cleanupOldLogs;
104
+ /**
105
+ * 获取日志文件列表
106
+ * @returns 日志文件列表
107
+ */
108
+ getLogFiles(): Promise<LogFile[]>;
109
+ /**
110
+ * 获取指定日志文件的内容
111
+ * @param fileName 日志文件名
112
+ * @returns 日志文件内容
113
+ */
114
+ getLogFile(fileName: string): Promise<LogFile | null>;
115
+ /**
116
+ * 清空指定日志文件
117
+ * @param fileName 日志文件名,不指定则清空所有日志
118
+ * @returns 是否成功
119
+ */
120
+ clearLogs(fileName?: string): Promise<boolean>;
121
+ /**
122
+ * 设置日志保留天数
123
+ * @param days 保留天数
124
+ */
125
+ setRetentionDays(days: number): void;
126
+ /**
127
+ * 手动触发清理旧日志
128
+ */
129
+ manualCleanup(): Promise<void>;
130
+ /**
131
+ * 销毁实例
132
+ */
133
+ destroy(): void;
134
+ }
135
+ export default LoggerManager;
@@ -20,7 +20,7 @@ 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 | React.ReactFragment | 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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.60",
3
+ "version": "1.0.62",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",