@hz-9/a5-core 0.2.0-alpha.46 → 0.2.0-alpha.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/dist/all.d.ts CHANGED
@@ -424,6 +424,33 @@ export declare class A5LoadPackageError extends Error {
424
424
  */
425
425
  export declare type A5ModuleConfigPath = `A5.${string}`;
426
426
 
427
+ /**
428
+ * A5 随机工具类
429
+ *
430
+ * 提供生成随机值和 UUID 的静态方法
431
+ *
432
+ * @public
433
+ */
434
+ export declare class A5RandomUtil {
435
+ static nanoid(size?: number): string;
436
+ static uuidV4(options?: V4Options): string;
437
+ static uuidV7(options?: V7Options): string;
438
+ /**
439
+ * 生成指定位数的随机数字
440
+ *
441
+ * @param digits - 位数,默认 6
442
+ * @returns 随机数字字符串
443
+ */
444
+ static randomDigits(digits?: number): string;
445
+ /**
446
+ * 生成指定长度的随机字符串(a-zA-Z0-9)
447
+ *
448
+ * @param length - 长度,默认 8
449
+ * @returns 随机字符串
450
+ */
451
+ static randomString(length?: number, chars?: string): string;
452
+ }
453
+
427
454
  /**
428
455
  * @public
429
456
  *
@@ -458,9 +485,6 @@ export declare class A5Util {
458
485
  * @returns 资源路径的绝对路径。
459
486
  */
460
487
  static tryWithAbsolutePath(sourcePath: string, basePath: string): string;
461
- static nanoid(size?: number): string;
462
- static uuidV4(options?: V4Options): string;
463
- static uuidV7(options?: V7Options): string;
464
488
  static getReqIdFromRequest(req: FastifyRequest): string;
465
489
  static getReqHeadersFromRequest(req: FastifyRequest): IncomingHttpHeaders;
466
490
  static getReqIdAndHeadersFromRequest(req: FastifyRequest): {
@@ -74,7 +74,7 @@ class A5Application {
74
74
  * setExtraUrl 及 getUrls 函数用于保存数据的数组
75
75
  */
76
76
  this.extraUrls = [];
77
- this.instanceId = util_1.A5Util.nanoid();
77
+ this.instanceId = util_1.A5RandomUtil.nanoid();
78
78
  this.nestApp = nestApp;
79
79
  this.options = {
80
80
  logger: options.logger ?? this._getA5LoggerService(),
@@ -37,7 +37,7 @@ class A5FactoryStatic {
37
37
  };
38
38
  const nestApplication = await this.nestFactoryStatic.create(module, new platform_fastify_1.FastifyAdapter({
39
39
  // 生成 Req Id
40
- genReqId: (req) => util_1.A5Util.uuidV7(),
40
+ genReqId: (req) => util_1.A5RandomUtil.uuidV7(),
41
41
  }), nestOptions);
42
42
  // this.initBodyParser(nestApplication, options)
43
43
  const app = new a5_application_1.A5Application(nestApplication);
@@ -1,6 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingHttpHeaders } from 'node:http';
3
- import { V4Options, V7Options } from 'uuid';
4
3
  import { FastifyRequest } from '../interface/http';
5
4
  /**
6
5
  *
@@ -28,9 +27,6 @@ export declare class A5Util {
28
27
  * @returns 资源路径的绝对路径。
29
28
  */
30
29
  static tryWithAbsolutePath(sourcePath: string, basePath: string): string;
31
- static nanoid(size?: number): string;
32
- static uuidV4(options?: V4Options): string;
33
- static uuidV7(options?: V7Options): string;
34
30
  static getReqIdFromRequest(req: FastifyRequest): string;
35
31
  static getReqHeadersFromRequest(req: FastifyRequest): IncomingHttpHeaders;
36
32
  static getReqIdAndHeadersFromRequest(req: FastifyRequest): {
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.A5Util = void 0;
4
- const nanoid_1 = require("nanoid");
5
4
  const upath_1 = require("upath");
6
- const uuid_1 = require("uuid");
7
5
  /**
8
6
  *
9
7
  * @public
@@ -38,15 +36,6 @@ class A5Util {
38
36
  ? (0, upath_1.normalize)(sourcePath)
39
37
  : (0, upath_1.resolve)((0, upath_1.normalize)(basePath), (0, upath_1.normalize)(sourcePath));
40
38
  }
41
- static nanoid(size) {
42
- return (0, nanoid_1.nanoid)(size);
43
- }
44
- static uuidV4(options) {
45
- return (0, uuid_1.v4)(options);
46
- }
47
- static uuidV7(options) {
48
- return (0, uuid_1.v7)(options);
49
- }
50
39
  static getReqIdFromRequest(req) {
51
40
  return req.id;
52
41
  }
@@ -2,4 +2,5 @@ export * from './a5.util';
2
2
  export * from './color.util';
3
3
  export * from './load-package.util';
4
4
  export * from './logo.util';
5
+ export * from './random.util';
5
6
  export * from './run-env.util';
@@ -18,5 +18,6 @@ __exportStar(require("./a5.util"), exports);
18
18
  __exportStar(require("./color.util"), exports);
19
19
  __exportStar(require("./load-package.util"), exports);
20
20
  __exportStar(require("./logo.util"), exports);
21
+ __exportStar(require("./random.util"), exports);
21
22
  __exportStar(require("./run-env.util"), exports);
22
23
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,27 @@
1
+ import { V4Options, V7Options } from 'uuid';
2
+ /**
3
+ * A5 随机工具类
4
+ *
5
+ * 提供生成随机值和 UUID 的静态方法
6
+ *
7
+ * @public
8
+ */
9
+ export declare class A5RandomUtil {
10
+ static nanoid(size?: number): string;
11
+ static uuidV4(options?: V4Options): string;
12
+ static uuidV7(options?: V7Options): string;
13
+ /**
14
+ * 生成指定位数的随机数字
15
+ *
16
+ * @param digits - 位数,默认 6
17
+ * @returns 随机数字字符串
18
+ */
19
+ static randomDigits(digits?: number): string;
20
+ /**
21
+ * 生成指定长度的随机字符串(a-zA-Z0-9)
22
+ *
23
+ * @param length - 长度,默认 8
24
+ * @returns 随机字符串
25
+ */
26
+ static randomString(length?: number, chars?: string): string;
27
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.A5RandomUtil = void 0;
4
+ const nanoid_1 = require("nanoid");
5
+ const uuid_1 = require("uuid");
6
+ /**
7
+ * A5 随机工具类
8
+ *
9
+ * 提供生成随机值和 UUID 的静态方法
10
+ *
11
+ * @public
12
+ */
13
+ class A5RandomUtil {
14
+ static nanoid(size) {
15
+ return (0, nanoid_1.nanoid)(size);
16
+ }
17
+ static uuidV4(options) {
18
+ return (0, uuid_1.v4)(options);
19
+ }
20
+ static uuidV7(options) {
21
+ return (0, uuid_1.v7)(options);
22
+ }
23
+ /**
24
+ * 生成指定位数的随机数字
25
+ *
26
+ * @param digits - 位数,默认 6
27
+ * @returns 随机数字字符串
28
+ */
29
+ static randomDigits(digits = 6) {
30
+ const min = 10 ** (digits - 1);
31
+ const max = 10 ** digits - 1;
32
+ const randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
33
+ return randomNum.toString();
34
+ }
35
+ /**
36
+ * 生成指定长度的随机字符串(a-zA-Z0-9)
37
+ *
38
+ * @param length - 长度,默认 8
39
+ * @returns 随机字符串
40
+ */
41
+ static randomString(length = 8, chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') {
42
+ return (0, nanoid_1.customAlphabet)(chars)(length);
43
+ }
44
+ }
45
+ exports.A5RandomUtil = A5RandomUtil;
46
+ //# sourceMappingURL=random.util.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hz-9/a5-core",
3
- "version": "0.2.0-alpha.46",
3
+ "version": "0.2.0-alpha.47",
4
4
  "description": "The core library for the `@hz-9/a5-*` series of repositories.",
5
5
  "keywords": [
6
6
  "nest",
@@ -40,7 +40,6 @@
40
40
  "@nestjs/platform-fastify": "^10.0.0",
41
41
  "@types/fs-extra": "~11.0.3",
42
42
  "@types/heft-jest": "~1.0.3",
43
- "@types/lodash": "~4.17.4",
44
43
  "@types/node": "~20.3.1",
45
44
  "@types/pug": "~2.0.10",
46
45
  "@types/uuid": "^10.0.0",
@@ -49,7 +48,6 @@
49
48
  "dayjs": "~1.11.10",
50
49
  "fastify": "4.28.1",
51
50
  "fs-extra": "~11.1.1",
52
- "lodash": "~4.17.21",
53
51
  "nanoid": "^3.3.7",
54
52
  "pug": "~3.0.3",
55
53
  "type-fest": "~4.20.0",