@hz-9/a5-core 0.2.0-alpha.4 → 0.2.0-alpha.41

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/dist/all.d.ts CHANGED
@@ -391,6 +391,27 @@ declare interface A5FormatMessageOptions {
391
391
  */
392
392
  export declare type A5GlobalProvideToken = `Global.A5.${string}`;
393
393
 
394
+ /**
395
+ * A5 加载包错误
396
+ * 当动态加载可选依赖包失败时抛出此错误
397
+ * @public
398
+ */
399
+ export declare class A5LoadPackageError extends Error {
400
+ /**
401
+ * 错误名称
402
+ */
403
+ readonly name: string;
404
+ /**
405
+ * 尝试加载的包名
406
+ */
407
+ readonly packageName: string;
408
+ /**
409
+ * 原始错误(如果有)
410
+ */
411
+ readonly cause?: Error;
412
+ constructor(packageName: string, message?: string, cause?: Error);
413
+ }
414
+
394
415
  /**
395
416
  * @public
396
417
  *
@@ -435,6 +456,13 @@ export declare class A5Util {
435
456
  static tryWithAbsolutePath(sourcePath: string, basePath: string): string;
436
457
  }
437
458
 
459
+ /**
460
+ * 类型断言工具 - 判断两个类型结构相似
461
+ *
462
+ * @public
463
+ */
464
+ export declare type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;
465
+
438
466
  /**
439
467
  * @public
440
468
  */
@@ -462,16 +490,67 @@ export declare class ColorUtil {
462
490
  static clear(text: string): string;
463
491
  }
464
492
 
493
+ /**
494
+ * 类型调试工具 - 展开类型定义
495
+ *
496
+ * @public
497
+ */
498
+ export declare type Debug<T> = {
499
+ [K in keyof T]: T[K];
500
+ };
501
+
465
502
  /**
466
503
  * @public
467
504
  */
468
505
  export declare const DEFAULT_LOG_LEVELS: LogLevel[];
469
506
 
507
+ /**
508
+ * 类型断言工具 - 判断两个类型相等
509
+ *
510
+ * @public
511
+ */
512
+ export declare type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
513
+
470
514
  /**
471
515
  * @public
472
516
  */
473
517
  export declare const ERROR_WELCOME_MSG: string;
474
518
 
519
+ /**
520
+ * 类型断言工具 - 期望类型为 true
521
+ *
522
+ * @public
523
+ */
524
+ export declare type Expect<T extends true> = T;
525
+
526
+ /**
527
+ * 类型断言工具 - 期望类型扩展自目标类型
528
+ *
529
+ * @public
530
+ */
531
+ export declare type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false;
532
+
533
+ /**
534
+ * 类型断言工具 - 期望值为 false
535
+ *
536
+ * @public
537
+ */
538
+ export declare type ExpectFalse<T extends false> = T;
539
+
540
+ /**
541
+ * 类型断言工具 - 期望值为 true
542
+ *
543
+ * @public
544
+ */
545
+ export declare type ExpectTrue<T extends true> = T;
546
+
547
+ /**
548
+ * 类型断言工具 - 验证函数参数类型
549
+ *
550
+ * @public
551
+ */
552
+ export declare type ExpectValidArgs<FUNC extends (...args: any[]) => any, ARGS extends any[]> = ARGS extends Parameters<FUNC> ? true : false;
553
+
475
554
  /**
476
555
  * @public
477
556
  */
@@ -535,6 +614,57 @@ export declare abstract class IA5ConfigModule {
535
614
  export declare abstract class IA5LogModule {
536
615
  }
537
616
 
617
+ /**
618
+ * 类型断言工具 - 判断是否为 any 类型
619
+ *
620
+ * @public
621
+ */
622
+ export declare type IsAny<T> = 0 extends 1 & T ? true : false;
623
+
624
+ /**
625
+ * 类型断言工具 - 判断是否为 false
626
+ *
627
+ * @public
628
+ */
629
+ export declare type IsFalse<T extends false> = T;
630
+
631
+ /**
632
+ * 类型断言工具 - 判断是否为 true
633
+ *
634
+ * @public
635
+ */
636
+ export declare type IsTrue<T extends true> = T;
637
+
638
+ /**
639
+ * JSON 数组类型
640
+ *
641
+ * 表示 JSON 数组结构,元素为任意 JSON 值
642
+ *
643
+ * @public
644
+ */
645
+ export declare interface JsonArray extends Array<JsonValue> {
646
+ }
647
+
648
+ /**
649
+ * JSON 对象类型
650
+ *
651
+ * 表示 JSON 对象结构,键为字符串,值为任意 JSON 值
652
+ *
653
+ * @public
654
+ */
655
+ export declare interface JsonObject {
656
+ [key: string]: JsonValue;
657
+ }
658
+
659
+ /**
660
+ * JSON 值类型
661
+ *
662
+ * 表示所有合法的 JSON 值类型,包括基础类型、对象和数组
663
+ *
664
+ * @public
665
+ */
666
+ export declare type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
667
+
538
668
  /**
539
669
  * 包加载工具类
540
670
  * 用于统一处理可选依赖的动态导入
@@ -547,13 +677,13 @@ export declare class LoadPackageUtil {
547
677
  * @returns 加载的包模块
548
678
  * @throws 当包加载失败时抛出错误
549
679
  */
550
- static loadPackage<T = unknown>(packageName: string): Promise<T>;
680
+ static loadPackage<T = unknown>(packageName: string): T;
551
681
  /**
552
682
  * 安全地动态加载包
553
683
  * @param packageName - 包名
554
684
  * @returns 加载的包模块,如果失败则返回 null
555
685
  */
556
- static loadPackageSafe<T = unknown>(packageName: string): Promise<T | null>;
686
+ static loadPackageSafe<T = unknown>(packageName: string): T | null;
557
687
  /**
558
688
  * 带重试的动态加载包
559
689
  * @param packageName - 包名
@@ -602,6 +732,15 @@ export declare class LogoUtil {
602
732
  */
603
733
  export declare const MAIN_STATIC_PATH: string;
604
734
 
735
+ /**
736
+ * 类型合并工具 - 合并嵌套类型
737
+ *
738
+ * @public
739
+ */
740
+ export declare type MergeInsertions<T> = T extends object ? {
741
+ [K in keyof T]: MergeInsertions<T[K]>;
742
+ } : T;
743
+
605
744
  /**
606
745
  *
607
746
  * @public
@@ -622,6 +761,20 @@ export declare const MODULE_CONFIG_PATH_A5_LOG: <T extends string>(str: T) => `A
622
761
 
623
762
  export { nanoid }
624
763
 
764
+ /**
765
+ * 类型断言工具 - 判断不是 any 类型
766
+ *
767
+ * @public
768
+ */
769
+ export declare type NotAny<T> = true extends IsAny<T> ? false : true;
770
+
771
+ /**
772
+ * 类型断言工具 - 判断两个类型不相等
773
+ *
774
+ * @public
775
+ */
776
+ export declare type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
777
+
625
778
  /**
626
779
  * @public
627
780
  */
@@ -661,6 +814,13 @@ export declare class RunEnvUtil {
661
814
  static get inJest(): boolean;
662
815
  }
663
816
 
817
+ /**
818
+ * 类型转换工具 - 联合类型转交叉类型
819
+ *
820
+ * @public
821
+ */
822
+ export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
823
+
664
824
  /**
665
825
  * @public
666
826
  */
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A5 加载包错误
3
+ * 当动态加载可选依赖包失败时抛出此错误
4
+ * @public
5
+ */
6
+ export declare class A5LoadPackageError extends Error {
7
+ /**
8
+ * 错误名称
9
+ */
10
+ readonly name: string;
11
+ /**
12
+ * 尝试加载的包名
13
+ */
14
+ readonly packageName: string;
15
+ /**
16
+ * 原始错误(如果有)
17
+ */
18
+ readonly cause?: Error;
19
+ constructor(packageName: string, message?: string, cause?: Error);
20
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.A5LoadPackageError = void 0;
4
+ /**
5
+ * A5 加载包错误
6
+ * 当动态加载可选依赖包失败时抛出此错误
7
+ * @public
8
+ */
9
+ class A5LoadPackageError extends Error {
10
+ constructor(packageName, message, cause) {
11
+ super(message || `Failed to load package: ${packageName}`);
12
+ /**
13
+ * 错误名称
14
+ */
15
+ this.name = 'A5LoadPackageError';
16
+ this.packageName = packageName;
17
+ this.cause = cause;
18
+ // 设置原型链,确保 instanceof 正常工作
19
+ Object.setPrototypeOf(this, A5LoadPackageError.prototype);
20
+ }
21
+ }
22
+ exports.A5LoadPackageError = A5LoadPackageError;
23
+ //# sourceMappingURL=a5-load-package.error.js.map
@@ -0,0 +1 @@
1
+ export * from './a5-load-package.error';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./a5-load-package.error"), exports);
18
+ //# sourceMappingURL=index.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './const';
2
2
  export * from './core';
3
+ export * from './errors';
3
4
  export * from './interface';
4
5
  export * from './module';
5
6
  export * from './middleware';
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./const"), exports);
18
18
  __exportStar(require("./core"), exports);
19
+ __exportStar(require("./errors"), exports);
19
20
  __exportStar(require("./interface"), exports);
20
21
  __exportStar(require("./module"), exports);
21
22
  __exportStar(require("./middleware"), exports);
@@ -1,3 +1,5 @@
1
1
  export * from './base';
2
2
  export * from './http';
3
+ export * from './json';
3
4
  export * from './provide-token';
5
+ export * from './type-challenges.utils';
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./base"), exports);
18
18
  __exportStar(require("./http"), exports);
19
+ __exportStar(require("./json"), exports);
19
20
  __exportStar(require("./provide-token"), exports);
21
+ __exportStar(require("./type-challenges.utils"), exports);
20
22
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * JSON 值类型
3
+ *
4
+ * 表示所有合法的 JSON 值类型,包括基础类型、对象和数组
5
+ *
6
+ * @public
7
+ */
8
+ export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
9
+ /**
10
+ * JSON 对象类型
11
+ *
12
+ * 表示 JSON 对象结构,键为字符串,值为任意 JSON 值
13
+ *
14
+ * @public
15
+ */
16
+ export interface JsonObject {
17
+ [key: string]: JsonValue;
18
+ }
19
+ /**
20
+ * JSON 数组类型
21
+ *
22
+ * 表示 JSON 数组结构,元素为任意 JSON 值
23
+ *
24
+ * @public
25
+ */
26
+ export interface JsonArray extends Array<JsonValue> {
27
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=json.js.map
@@ -0,0 +1,94 @@
1
+ /**
2
+ * 类型断言工具 - 期望类型为 true
3
+ *
4
+ * @public
5
+ */
6
+ export type Expect<T extends true> = T;
7
+ /**
8
+ * 类型断言工具 - 期望值为 true
9
+ *
10
+ * @public
11
+ */
12
+ export type ExpectTrue<T extends true> = T;
13
+ /**
14
+ * 类型断言工具 - 期望值为 false
15
+ *
16
+ * @public
17
+ */
18
+ export type ExpectFalse<T extends false> = T;
19
+ /**
20
+ * 类型断言工具 - 判断是否为 true
21
+ *
22
+ * @public
23
+ */
24
+ export type IsTrue<T extends true> = T;
25
+ /**
26
+ * 类型断言工具 - 判断是否为 false
27
+ *
28
+ * @public
29
+ */
30
+ export type IsFalse<T extends false> = T;
31
+ /**
32
+ * 类型断言工具 - 判断两个类型不相等
33
+ *
34
+ * @public
35
+ */
36
+ export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
37
+ /**
38
+ * 类型断言工具 - 判断两个类型相等
39
+ *
40
+ * @public
41
+ */
42
+ export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
43
+ /**
44
+ * 类型断言工具 - 判断是否为 any 类型
45
+ *
46
+ * @public
47
+ */
48
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
49
+ /**
50
+ * 类型断言工具 - 判断不是 any 类型
51
+ *
52
+ * @public
53
+ */
54
+ export type NotAny<T> = true extends IsAny<T> ? false : true;
55
+ /**
56
+ * 类型调试工具 - 展开类型定义
57
+ *
58
+ * @public
59
+ */
60
+ export type Debug<T> = {
61
+ [K in keyof T]: T[K];
62
+ };
63
+ /**
64
+ * 类型合并工具 - 合并嵌套类型
65
+ *
66
+ * @public
67
+ */
68
+ export type MergeInsertions<T> = T extends object ? {
69
+ [K in keyof T]: MergeInsertions<T[K]>;
70
+ } : T;
71
+ /**
72
+ * 类型断言工具 - 判断两个类型结构相似
73
+ *
74
+ * @public
75
+ */
76
+ export type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;
77
+ /**
78
+ * 类型断言工具 - 期望类型扩展自目标类型
79
+ *
80
+ * @public
81
+ */
82
+ export type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false;
83
+ /**
84
+ * 类型断言工具 - 验证函数参数类型
85
+ *
86
+ * @public
87
+ */
88
+ export type ExpectValidArgs<FUNC extends (...args: any[]) => any, ARGS extends any[]> = ARGS extends Parameters<FUNC> ? true : false;
89
+ /**
90
+ * 类型转换工具 - 联合类型转交叉类型
91
+ *
92
+ * @public
93
+ */
94
+ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=type-challenges.utils.js.map
@@ -10,10 +10,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  /* eslint-disable @typescript-eslint/consistent-type-definitions */
13
- const core_1 = require("../../../core");
14
- const util_1 = require("../../../util");
15
13
  const node_console_1 = __importDefault(require("node:console"));
16
14
  const common_1 = require("@nestjs/common");
15
+ const core_1 = require("../../../core");
16
+ const util_1 = require("../../../util");
17
17
  describe('A5Factory', () => {
18
18
  describe('create', () => {
19
19
  describe('printLogo', () => {
@@ -10,13 +10,13 @@ export declare class LoadPackageUtil {
10
10
  * @returns 加载的包模块
11
11
  * @throws 当包加载失败时抛出错误
12
12
  */
13
- static loadPackage<T = unknown>(packageName: string): Promise<T>;
13
+ static loadPackage<T = unknown>(packageName: string): T;
14
14
  /**
15
15
  * 安全地动态加载包
16
16
  * @param packageName - 包名
17
17
  * @returns 加载的包模块,如果失败则返回 null
18
18
  */
19
- static loadPackageSafe<T = unknown>(packageName: string): Promise<T | null>;
19
+ static loadPackageSafe<T = unknown>(packageName: string): T | null;
20
20
  /**
21
21
  * 带重试的动态加载包
22
22
  * @param packageName - 包名
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LoadPackageUtil = void 0;
4
+ const errors_1 = require("../errors");
4
5
  const a5_util_1 = require("./a5.util");
5
6
  // TODO 当前文件,并未编写单元测试
6
7
  /**
@@ -15,7 +16,7 @@ class LoadPackageUtil {
15
16
  * @returns 加载的包模块
16
17
  * @throws 当包加载失败时抛出错误
17
18
  */
18
- static async loadPackage(packageName) {
19
+ static loadPackage(packageName) {
19
20
  try {
20
21
  // 使用 Dynimic_import 引入模块,仍会显示 ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG 报错,
21
22
  // 使用 require 进行动态引入;
@@ -25,8 +26,10 @@ class LoadPackageUtil {
25
26
  return module;
26
27
  }
27
28
  catch (error) {
28
- // TODO 优化报错显示
29
- throw new Error(`Failed to load package "${packageName}": ${error instanceof Error ? error.message : String(error)}`);
29
+ // 抛出 A5LoadPackageError 错误
30
+ const cause = error instanceof Error ? error : undefined;
31
+ const message = error instanceof Error ? error.message : String(error);
32
+ throw new errors_1.A5LoadPackageError(packageName, `Failed to load package "${packageName}": ${message}`, cause);
30
33
  }
31
34
  }
32
35
  /**
@@ -34,9 +37,9 @@ class LoadPackageUtil {
34
37
  * @param packageName - 包名
35
38
  * @returns 加载的包模块,如果失败则返回 null
36
39
  */
37
- static async loadPackageSafe(packageName) {
40
+ static loadPackageSafe(packageName) {
38
41
  try {
39
- return await LoadPackageUtil.loadPackage(packageName);
42
+ return LoadPackageUtil.loadPackage(packageName);
40
43
  }
41
44
  catch {
42
45
  return null;
@@ -54,7 +57,7 @@ class LoadPackageUtil {
54
57
  let lastError = null;
55
58
  for (let i = 0; i <= retries; i += 1) {
56
59
  try {
57
- return await LoadPackageUtil.loadPackage(packageName);
60
+ return LoadPackageUtil.loadPackage(packageName);
58
61
  }
59
62
  catch (error) {
60
63
  lastError = error instanceof Error ? error : new Error(String(error));
@@ -64,7 +67,8 @@ class LoadPackageUtil {
64
67
  }
65
68
  }
66
69
  }
67
- throw lastError || new Error(`Failed to load package "${packageName}" after ${retries + 1} attempts`);
70
+ throw (lastError ||
71
+ new errors_1.A5LoadPackageError(packageName, `Failed to load package "${packageName}" after ${retries + 1} attempts`));
68
72
  }
69
73
  }
70
74
  exports.LoadPackageUtil = LoadPackageUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hz-9/a5-core",
3
- "version": "0.2.0-alpha.4",
3
+ "version": "0.2.0-alpha.41",
4
4
  "description": "The core library for the `@hz-9/a5-*` series of repositories.",
5
5
  "keywords": [
6
6
  "nest",
@@ -45,7 +45,6 @@
45
45
  "@types/node": "~20.3.1",
46
46
  "@types/pug": "~2.0.10",
47
47
  "@types/uuid": "~9.0.8",
48
- "@type-challenges/utils": "~0.1.1",
49
48
  "axios": "~1.7.2",
50
49
  "body-parser": "~1.20.2",
51
50
  "dayjs": "~1.11.10",
@@ -62,7 +61,6 @@
62
61
  "@nestjs/cli": "^10.0.0",
63
62
  "@nestjs/common": "^10.0.0",
64
63
  "@nestjs/core": "^10.0.0",
65
- "@nestjs/swagger": "~7.1.14",
66
64
  "@nestjs/testing": "^10.0.0",
67
65
  "@rushstack/heft": "0.66.1",
68
66
  "@types/body-parser": "~1.19.5",