@hz-9/a5-core 0.2.0-alpha.6 → 0.2.0-alpha.60
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 +270 -5
- package/dist/core/a5-application.d.ts +20 -1
- package/dist/core/a5-application.js +8 -3
- package/dist/core/a5-console-logger.js +5 -10
- package/dist/core/a5-factory.js +4 -1
- package/dist/errors/a5-load-package.error.d.ts +20 -0
- package/dist/errors/a5-load-package.error.js +23 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interface/index.d.ts +2 -0
- package/dist/interface/index.js +2 -0
- package/dist/interface/json.d.ts +27 -0
- package/dist/interface/json.js +3 -0
- package/dist/interface/type-challenges.utils.d.ts +94 -0
- package/dist/interface/type-challenges.utils.js +4 -0
- package/dist/plugins/axios.d.ts +2 -0
- package/dist/plugins/axios.js +7 -0
- package/dist/plugins/dayjs.d.ts +2 -0
- package/dist/plugins/dayjs.js +7 -0
- package/dist/plugins/fs-extra.d.ts +2 -0
- package/dist/plugins/fs-extra.js +7 -0
- package/dist/plugins/ms.d.ts +2 -0
- package/dist/plugins/ms.js +7 -0
- package/dist/plugins/nanoid.d.ts +2 -1
- package/dist/plugins/nanoid.js +2 -4
- package/dist/plugins/pug.d.ts +2 -0
- package/dist/plugins/pug.js +7 -0
- package/dist/plugins/type-fest.d.ts +1 -0
- package/dist/plugins/{index.js → type-fest.js} +2 -2
- package/dist/plugins/ua-parser-js.d.ts +2 -0
- package/dist/plugins/ua-parser-js.js +7 -0
- package/dist/plugins/upath.d.ts +2 -0
- package/dist/plugins/upath.js +7 -0
- package/dist/plugins/uuid.d.ts +2 -0
- package/dist/plugins/uuid.js +27 -0
- package/dist/test/integration/core/a5-factory.integration.spec.js +2 -2
- package/dist/util/a5.util.d.ts +9 -0
- package/dist/util/a5.util.js +13 -0
- package/dist/util/index.d.ts +2 -0
- package/dist/util/index.js +2 -0
- package/dist/util/load-package.util.d.ts +2 -2
- package/dist/util/load-package.util.js +11 -7
- package/dist/util/ms.util.d.ts +47 -0
- package/dist/util/ms.util.js +66 -0
- package/dist/util/random.util.d.ts +27 -0
- package/dist/util/random.util.js +46 -0
- package/package.json +47 -8
- package/dist/plugins/index.d.ts +0 -1
package/dist/all.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
1
3
|
import { FastifyReply as FastifyReply_2 } from 'fastify';
|
|
2
4
|
import { FastifyRequest as FastifyRequest_2 } from 'fastify';
|
|
5
|
+
import { IncomingHttpHeaders } from 'node:http';
|
|
3
6
|
import { Logger } from '@nestjs/common';
|
|
4
7
|
import { LoggerService } from '@nestjs/common/services/logger.service';
|
|
5
8
|
import { LoggerService as LoggerService_2 } from '@nestjs/common';
|
|
6
9
|
import { LogLevel } from '@nestjs/common/services/logger.service';
|
|
7
|
-
import
|
|
10
|
+
import ms from 'ms';
|
|
8
11
|
import { NestFactoryStatic } from '@nestjs/core/nest-factory';
|
|
9
12
|
import { NestFastifyApplication } from '@nestjs/platform-fastify';
|
|
10
13
|
import { NestMiddleware } from '@nestjs/common';
|
|
14
|
+
import { V4Options } from 'uuid';
|
|
15
|
+
import { V7Options } from 'uuid';
|
|
11
16
|
|
|
12
17
|
/**
|
|
13
18
|
* @public
|
|
@@ -118,7 +123,7 @@ export declare class A5Application {
|
|
|
118
123
|
* 在正常获取 IP 与端口后,可通过此函数输出日志信息。
|
|
119
124
|
*
|
|
120
125
|
*/
|
|
121
|
-
printAddress(): Promise<void>;
|
|
126
|
+
printAddress(options?: A5AppPrintAddressOptions): Promise<void>;
|
|
122
127
|
/**
|
|
123
128
|
*
|
|
124
129
|
* @public
|
|
@@ -193,6 +198,27 @@ export declare interface A5AppListenOptions {
|
|
|
193
198
|
*/
|
|
194
199
|
export declare type A5AppOptions = Required<A5AppConstructorOptions>;
|
|
195
200
|
|
|
201
|
+
/**
|
|
202
|
+
* @public
|
|
203
|
+
*
|
|
204
|
+
* A5App 打印地址项
|
|
205
|
+
*
|
|
206
|
+
*/
|
|
207
|
+
export declare interface A5AppPrintAddressItem {
|
|
208
|
+
name: string;
|
|
209
|
+
path: string;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @public
|
|
214
|
+
*
|
|
215
|
+
* A5App 打印地址选项
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
218
|
+
export declare interface A5AppPrintAddressOptions {
|
|
219
|
+
address?: A5AppPrintAddressItem[];
|
|
220
|
+
}
|
|
221
|
+
|
|
196
222
|
/**
|
|
197
223
|
* @public
|
|
198
224
|
*/
|
|
@@ -391,6 +417,27 @@ declare interface A5FormatMessageOptions {
|
|
|
391
417
|
*/
|
|
392
418
|
export declare type A5GlobalProvideToken = `Global.A5.${string}`;
|
|
393
419
|
|
|
420
|
+
/**
|
|
421
|
+
* A5 加载包错误
|
|
422
|
+
* 当动态加载可选依赖包失败时抛出此错误
|
|
423
|
+
* @public
|
|
424
|
+
*/
|
|
425
|
+
export declare class A5LoadPackageError extends Error {
|
|
426
|
+
/**
|
|
427
|
+
* 错误名称
|
|
428
|
+
*/
|
|
429
|
+
readonly name: string;
|
|
430
|
+
/**
|
|
431
|
+
* 尝试加载的包名
|
|
432
|
+
*/
|
|
433
|
+
readonly packageName: string;
|
|
434
|
+
/**
|
|
435
|
+
* 原始错误(如果有)
|
|
436
|
+
*/
|
|
437
|
+
readonly cause?: Error;
|
|
438
|
+
constructor(packageName: string, message?: string, cause?: Error);
|
|
439
|
+
}
|
|
440
|
+
|
|
394
441
|
/**
|
|
395
442
|
* @public
|
|
396
443
|
*
|
|
@@ -399,6 +446,33 @@ export declare type A5GlobalProvideToken = `Global.A5.${string}`;
|
|
|
399
446
|
*/
|
|
400
447
|
export declare type A5ModuleConfigPath = `A5.${string}`;
|
|
401
448
|
|
|
449
|
+
/**
|
|
450
|
+
* A5 随机工具类
|
|
451
|
+
*
|
|
452
|
+
* 提供生成随机值和 UUID 的静态方法
|
|
453
|
+
*
|
|
454
|
+
* @public
|
|
455
|
+
*/
|
|
456
|
+
export declare class A5RandomUtil {
|
|
457
|
+
static nanoid(size?: number): string;
|
|
458
|
+
static uuidV4(options?: V4Options): string;
|
|
459
|
+
static uuidV7(options?: V7Options): string;
|
|
460
|
+
/**
|
|
461
|
+
* 生成指定位数的随机数字
|
|
462
|
+
*
|
|
463
|
+
* @param digits - 位数,默认 6
|
|
464
|
+
* @returns 随机数字字符串
|
|
465
|
+
*/
|
|
466
|
+
static randomDigits(digits?: number): string;
|
|
467
|
+
/**
|
|
468
|
+
* 生成指定长度的随机字符串(a-zA-Z0-9)
|
|
469
|
+
*
|
|
470
|
+
* @param length - 长度,默认 8
|
|
471
|
+
* @returns 随机字符串
|
|
472
|
+
*/
|
|
473
|
+
static randomString(length?: number, chars?: string): string;
|
|
474
|
+
}
|
|
475
|
+
|
|
402
476
|
/**
|
|
403
477
|
* @public
|
|
404
478
|
*
|
|
@@ -433,8 +507,21 @@ export declare class A5Util {
|
|
|
433
507
|
* @returns 资源路径的绝对路径。
|
|
434
508
|
*/
|
|
435
509
|
static tryWithAbsolutePath(sourcePath: string, basePath: string): string;
|
|
510
|
+
static getReqIdFromRequest(req: FastifyRequest): string;
|
|
511
|
+
static getReqHeadersFromRequest(req: FastifyRequest): IncomingHttpHeaders;
|
|
512
|
+
static getReqIdAndHeadersFromRequest(req: FastifyRequest): {
|
|
513
|
+
reqId: string;
|
|
514
|
+
reqHeaders: IncomingHttpHeaders;
|
|
515
|
+
};
|
|
436
516
|
}
|
|
437
517
|
|
|
518
|
+
/**
|
|
519
|
+
* 类型断言工具 - 判断两个类型结构相似
|
|
520
|
+
*
|
|
521
|
+
* @public
|
|
522
|
+
*/
|
|
523
|
+
export declare type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;
|
|
524
|
+
|
|
438
525
|
/**
|
|
439
526
|
* @public
|
|
440
527
|
*/
|
|
@@ -462,16 +549,67 @@ export declare class ColorUtil {
|
|
|
462
549
|
static clear(text: string): string;
|
|
463
550
|
}
|
|
464
551
|
|
|
552
|
+
/**
|
|
553
|
+
* 类型调试工具 - 展开类型定义
|
|
554
|
+
*
|
|
555
|
+
* @public
|
|
556
|
+
*/
|
|
557
|
+
export declare type Debug<T> = {
|
|
558
|
+
[K in keyof T]: T[K];
|
|
559
|
+
};
|
|
560
|
+
|
|
465
561
|
/**
|
|
466
562
|
* @public
|
|
467
563
|
*/
|
|
468
564
|
export declare const DEFAULT_LOG_LEVELS: LogLevel[];
|
|
469
565
|
|
|
566
|
+
/**
|
|
567
|
+
* 类型断言工具 - 判断两个类型相等
|
|
568
|
+
*
|
|
569
|
+
* @public
|
|
570
|
+
*/
|
|
571
|
+
export declare type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
572
|
+
|
|
470
573
|
/**
|
|
471
574
|
* @public
|
|
472
575
|
*/
|
|
473
576
|
export declare const ERROR_WELCOME_MSG: string;
|
|
474
577
|
|
|
578
|
+
/**
|
|
579
|
+
* 类型断言工具 - 期望类型为 true
|
|
580
|
+
*
|
|
581
|
+
* @public
|
|
582
|
+
*/
|
|
583
|
+
export declare type Expect<T extends true> = T;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* 类型断言工具 - 期望类型扩展自目标类型
|
|
587
|
+
*
|
|
588
|
+
* @public
|
|
589
|
+
*/
|
|
590
|
+
export declare type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE ? true : false;
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* 类型断言工具 - 期望值为 false
|
|
594
|
+
*
|
|
595
|
+
* @public
|
|
596
|
+
*/
|
|
597
|
+
export declare type ExpectFalse<T extends false> = T;
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* 类型断言工具 - 期望值为 true
|
|
601
|
+
*
|
|
602
|
+
* @public
|
|
603
|
+
*/
|
|
604
|
+
export declare type ExpectTrue<T extends true> = T;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* 类型断言工具 - 验证函数参数类型
|
|
608
|
+
*
|
|
609
|
+
* @public
|
|
610
|
+
*/
|
|
611
|
+
export declare type ExpectValidArgs<FUNC extends (...args: any[]) => any, ARGS extends any[]> = ARGS extends Parameters<FUNC> ? true : false;
|
|
612
|
+
|
|
475
613
|
/**
|
|
476
614
|
* @public
|
|
477
615
|
*/
|
|
@@ -535,6 +673,57 @@ export declare abstract class IA5ConfigModule {
|
|
|
535
673
|
export declare abstract class IA5LogModule {
|
|
536
674
|
}
|
|
537
675
|
|
|
676
|
+
/**
|
|
677
|
+
* 类型断言工具 - 判断是否为 any 类型
|
|
678
|
+
*
|
|
679
|
+
* @public
|
|
680
|
+
*/
|
|
681
|
+
export declare type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* 类型断言工具 - 判断是否为 false
|
|
685
|
+
*
|
|
686
|
+
* @public
|
|
687
|
+
*/
|
|
688
|
+
export declare type IsFalse<T extends false> = T;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* 类型断言工具 - 判断是否为 true
|
|
692
|
+
*
|
|
693
|
+
* @public
|
|
694
|
+
*/
|
|
695
|
+
export declare type IsTrue<T extends true> = T;
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* JSON 数组类型
|
|
699
|
+
*
|
|
700
|
+
* 表示 JSON 数组结构,元素为任意 JSON 值
|
|
701
|
+
*
|
|
702
|
+
* @public
|
|
703
|
+
*/
|
|
704
|
+
export declare interface JsonArray extends Array<JsonValue> {
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* JSON 对象类型
|
|
709
|
+
*
|
|
710
|
+
* 表示 JSON 对象结构,键为字符串,值为任意 JSON 值
|
|
711
|
+
*
|
|
712
|
+
* @public
|
|
713
|
+
*/
|
|
714
|
+
export declare interface JsonObject {
|
|
715
|
+
[key: string]: JsonValue;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* JSON 值类型
|
|
720
|
+
*
|
|
721
|
+
* 表示所有合法的 JSON 值类型,包括基础类型、对象和数组
|
|
722
|
+
*
|
|
723
|
+
* @public
|
|
724
|
+
*/
|
|
725
|
+
export declare type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
|
|
726
|
+
|
|
538
727
|
/**
|
|
539
728
|
* 包加载工具类
|
|
540
729
|
* 用于统一处理可选依赖的动态导入
|
|
@@ -547,13 +736,13 @@ export declare class LoadPackageUtil {
|
|
|
547
736
|
* @returns 加载的包模块
|
|
548
737
|
* @throws 当包加载失败时抛出错误
|
|
549
738
|
*/
|
|
550
|
-
static loadPackage<T = unknown>(packageName: string):
|
|
739
|
+
static loadPackage<T = unknown>(packageName: string): T;
|
|
551
740
|
/**
|
|
552
741
|
* 安全地动态加载包
|
|
553
742
|
* @param packageName - 包名
|
|
554
743
|
* @returns 加载的包模块,如果失败则返回 null
|
|
555
744
|
*/
|
|
556
|
-
static loadPackageSafe<T = unknown>(packageName: string):
|
|
745
|
+
static loadPackageSafe<T = unknown>(packageName: string): T | null;
|
|
557
746
|
/**
|
|
558
747
|
* 带重试的动态加载包
|
|
559
748
|
* @param packageName - 包名
|
|
@@ -602,6 +791,15 @@ export declare class LogoUtil {
|
|
|
602
791
|
*/
|
|
603
792
|
export declare const MAIN_STATIC_PATH: string;
|
|
604
793
|
|
|
794
|
+
/**
|
|
795
|
+
* 类型合并工具 - 合并嵌套类型
|
|
796
|
+
*
|
|
797
|
+
* @public
|
|
798
|
+
*/
|
|
799
|
+
export declare type MergeInsertions<T> = T extends object ? {
|
|
800
|
+
[K in keyof T]: MergeInsertions<T[K]>;
|
|
801
|
+
} : T;
|
|
802
|
+
|
|
605
803
|
/**
|
|
606
804
|
*
|
|
607
805
|
* @public
|
|
@@ -620,7 +818,67 @@ export declare const MODULE_CONFIG_PATH_A5_CONFIG: <T extends string>(str: T) =>
|
|
|
620
818
|
*/
|
|
621
819
|
export declare const MODULE_CONFIG_PATH_A5_LOG: <T extends string>(str: T) => `A5.log.${T}`;
|
|
622
820
|
|
|
623
|
-
|
|
821
|
+
/**
|
|
822
|
+
* @public
|
|
823
|
+
*/
|
|
824
|
+
export declare type MSStringValue = ms.StringValue;
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* @public
|
|
828
|
+
*/
|
|
829
|
+
export declare class MSUtil {
|
|
830
|
+
/**
|
|
831
|
+
* 将 ms 时间字符串转换为毫秒数
|
|
832
|
+
*
|
|
833
|
+
* @param value - ms 时间字符串
|
|
834
|
+
* @returns 毫秒数
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```typescript
|
|
838
|
+
* MSUtil.ms('123') // 123
|
|
839
|
+
* MSUtil.ms('2h') // 7200000
|
|
840
|
+
* MSUtil.ms('30s') // 30000
|
|
841
|
+
* MSUtil.ms('123 ms') // 123
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
static ms(value: ms.StringValue): number;
|
|
845
|
+
/**
|
|
846
|
+
* 判断字符串是否是有效的 ms 时间字符串格式
|
|
847
|
+
* 可以作为类型守卫使用,在运行时验证并断言为 ms.StringValue 类型
|
|
848
|
+
*
|
|
849
|
+
* @param value - 要检查的字符串值
|
|
850
|
+
* @returns 如果是有效的 ms 字符串返回 true,否则返回 false
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* ```typescript
|
|
854
|
+
* // 有效格式
|
|
855
|
+
* MSUtil.isMsStringValue('123') // true
|
|
856
|
+
* MSUtil.isMsStringValue('2h') // true
|
|
857
|
+
* MSUtil.isMsStringValue('30s') // true
|
|
858
|
+
* MSUtil.isMsStringValue('123 ms') // true
|
|
859
|
+
*
|
|
860
|
+
* // 无效格式
|
|
861
|
+
* MSUtil.isMsStringValue('abc') // false
|
|
862
|
+
* MSUtil.isMsStringValue('') // false
|
|
863
|
+
* MSUtil.isMsStringValue('123xx') // false
|
|
864
|
+
* ```
|
|
865
|
+
*/
|
|
866
|
+
static isMsStringValue(value: string): value is ms.StringValue;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* 类型断言工具 - 判断不是 any 类型
|
|
871
|
+
*
|
|
872
|
+
* @public
|
|
873
|
+
*/
|
|
874
|
+
export declare type NotAny<T> = true extends IsAny<T> ? false : true;
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* 类型断言工具 - 判断两个类型不相等
|
|
878
|
+
*
|
|
879
|
+
* @public
|
|
880
|
+
*/
|
|
881
|
+
export declare type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
|
|
624
882
|
|
|
625
883
|
/**
|
|
626
884
|
* @public
|
|
@@ -661,6 +919,13 @@ export declare class RunEnvUtil {
|
|
|
661
919
|
static get inJest(): boolean;
|
|
662
920
|
}
|
|
663
921
|
|
|
922
|
+
/**
|
|
923
|
+
* 类型转换工具 - 联合类型转交叉类型
|
|
924
|
+
*
|
|
925
|
+
* @public
|
|
926
|
+
*/
|
|
927
|
+
export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
928
|
+
|
|
664
929
|
/**
|
|
665
930
|
* @public
|
|
666
931
|
*/
|
|
@@ -63,6 +63,25 @@ export interface A5AppListenOptions {
|
|
|
63
63
|
*/
|
|
64
64
|
readonly tryTimes?: number;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* @public
|
|
68
|
+
*
|
|
69
|
+
* A5App 打印地址项
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
export interface A5AppPrintAddressItem {
|
|
73
|
+
name: string;
|
|
74
|
+
path: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @public
|
|
78
|
+
*
|
|
79
|
+
* A5App 打印地址选项
|
|
80
|
+
*
|
|
81
|
+
*/
|
|
82
|
+
export interface A5AppPrintAddressOptions {
|
|
83
|
+
address?: A5AppPrintAddressItem[];
|
|
84
|
+
}
|
|
66
85
|
/**
|
|
67
86
|
* @public
|
|
68
87
|
*
|
|
@@ -126,7 +145,7 @@ export declare class A5Application {
|
|
|
126
145
|
* 在正常获取 IP 与端口后,可通过此函数输出日志信息。
|
|
127
146
|
*
|
|
128
147
|
*/
|
|
129
|
-
printAddress(): Promise<void>;
|
|
148
|
+
printAddress(options?: A5AppPrintAddressOptions): Promise<void>;
|
|
130
149
|
/**
|
|
131
150
|
*
|
|
132
151
|
* @public
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.A5Application = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const core_1 = require("@nestjs/core");
|
|
6
|
-
const nanoid_1 = require("nanoid");
|
|
7
6
|
const index_1 = require("../const/index");
|
|
8
7
|
const log_1 = require("../module/log");
|
|
9
8
|
const util_1 = require("../util");
|
|
@@ -75,7 +74,7 @@ class A5Application {
|
|
|
75
74
|
* setExtraUrl 及 getUrls 函数用于保存数据的数组
|
|
76
75
|
*/
|
|
77
76
|
this.extraUrls = [];
|
|
78
|
-
this.instanceId =
|
|
77
|
+
this.instanceId = util_1.A5RandomUtil.nanoid();
|
|
79
78
|
this.nestApp = nestApp;
|
|
80
79
|
this.options = {
|
|
81
80
|
logger: options.logger ?? this._getA5LoggerService(),
|
|
@@ -195,7 +194,7 @@ class A5Application {
|
|
|
195
194
|
* 在正常获取 IP 与端口后,可通过此函数输出日志信息。
|
|
196
195
|
*
|
|
197
196
|
*/
|
|
198
|
-
async printAddress() {
|
|
197
|
+
async printAddress(options) {
|
|
199
198
|
const urls = await this.getUrls();
|
|
200
199
|
const timeDiffWithColor = util_1.ColorUtil.yellowBright(`${Date.now() - +process.env.A5_INIT_TIME} ms`);
|
|
201
200
|
const urlMaxLength = Math.max(...urls.map((i) => i.length));
|
|
@@ -208,6 +207,12 @@ class A5Application {
|
|
|
208
207
|
this.logger.log(` ${urlWithColor}`);
|
|
209
208
|
}
|
|
210
209
|
});
|
|
210
|
+
if (Array.isArray(options?.address)) {
|
|
211
|
+
options?.address.forEach((address) => {
|
|
212
|
+
const urlWithColor = util_1.ColorUtil.cyan(`${urls[0] ?? ''}${address.path}`);
|
|
213
|
+
this.logger.log(`${address.name.padEnd(21, ' ')} ${urlWithColor}`);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
211
216
|
}
|
|
212
217
|
/**
|
|
213
218
|
*
|
|
@@ -11,6 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
14
17
|
var A5ConsoleLogger_1;
|
|
15
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
19
|
exports.A5ConsoleLogger = exports.DEFAULT_LOG_LEVELS = void 0;
|
|
@@ -20,19 +23,11 @@ const optional_decorator_1 = require("@nestjs/common/decorators/core/optional.de
|
|
|
20
23
|
const is_log_level_enabled_util_1 = require("@nestjs/common/services/utils/is-log-level-enabled.util");
|
|
21
24
|
const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
|
|
22
25
|
const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
|
26
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
23
27
|
/**
|
|
24
28
|
* @public
|
|
25
29
|
*/
|
|
26
30
|
exports.DEFAULT_LOG_LEVELS = ['log', 'error', 'warn', 'debug', 'verbose', 'fatal'];
|
|
27
|
-
const dateTimeFormatter = new Intl.DateTimeFormat(undefined, {
|
|
28
|
-
year: 'numeric',
|
|
29
|
-
month: '2-digit',
|
|
30
|
-
day: '2-digit',
|
|
31
|
-
hour: 'numeric',
|
|
32
|
-
minute: 'numeric',
|
|
33
|
-
second: 'numeric',
|
|
34
|
-
fractionalSecondDigits: 3,
|
|
35
|
-
});
|
|
36
31
|
/**
|
|
37
32
|
* @public
|
|
38
33
|
*/
|
|
@@ -185,7 +180,7 @@ let A5ConsoleLogger = A5ConsoleLogger_1 = class A5ConsoleLogger {
|
|
|
185
180
|
return logLevel.toUpperCase().padStart(7, ' ');
|
|
186
181
|
}
|
|
187
182
|
formatTimestamp(dateMilliseconds) {
|
|
188
|
-
return
|
|
183
|
+
return (0, dayjs_1.default)(dateMilliseconds).format('YYYY-MM-DDTHH:mm:ss.SSS');
|
|
189
184
|
}
|
|
190
185
|
formatContext(context) {
|
|
191
186
|
if (context.length === 0)
|
package/dist/core/a5-factory.js
CHANGED
|
@@ -35,7 +35,10 @@ class A5FactoryStatic {
|
|
|
35
35
|
const nestOptions = {
|
|
36
36
|
bufferLogs: true,
|
|
37
37
|
};
|
|
38
|
-
const nestApplication = await this.nestFactoryStatic.create(module, new platform_fastify_1.FastifyAdapter(
|
|
38
|
+
const nestApplication = await this.nestFactoryStatic.create(module, new platform_fastify_1.FastifyAdapter({
|
|
39
|
+
// 生成 Req Id
|
|
40
|
+
genReqId: (req) => util_1.A5RandomUtil.uuidV7(),
|
|
41
|
+
}), nestOptions);
|
|
39
42
|
// this.initBodyParser(nestApplication, options)
|
|
40
43
|
const app = new a5_application_1.A5Application(nestApplication);
|
|
41
44
|
await app.init();
|
|
@@ -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
package/dist/index.js
CHANGED
|
@@ -16,9 +16,9 @@ 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);
|
|
22
|
-
__exportStar(require("./plugins"), exports);
|
|
23
23
|
__exportStar(require("./util"), exports);
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
package/dist/interface/index.js
CHANGED
|
@@ -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
|
+
}
|