@hz-9/a5-core 0.2.0-alpha.1

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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/all.d.ts +676 -0
  4. package/dist/const/index.d.ts +38 -0
  5. package/dist/const/index.js +46 -0
  6. package/dist/core/__import-reflect-metadata.d.ts +1 -0
  7. package/dist/core/__import-reflect-metadata.js +4 -0
  8. package/dist/core/a5-application.d.ts +154 -0
  9. package/dist/core/a5-application.js +315 -0
  10. package/dist/core/a5-console-logger.d.ts +163 -0
  11. package/dist/core/a5-console-logger.js +354 -0
  12. package/dist/core/a5-factory.d.ts +21 -0
  13. package/dist/core/a5-factory.js +49 -0
  14. package/dist/core/index.d.ts +3 -0
  15. package/dist/core/index.js +20 -0
  16. package/dist/index.d.ts +7 -0
  17. package/dist/index.js +24 -0
  18. package/dist/interface/base.d.ts +18 -0
  19. package/dist/interface/base.js +3 -0
  20. package/dist/interface/http.d.ts +16 -0
  21. package/dist/interface/http.js +3 -0
  22. package/dist/interface/index.d.ts +3 -0
  23. package/dist/interface/index.js +20 -0
  24. package/dist/interface/provide-token.d.ts +21 -0
  25. package/dist/interface/provide-token.js +3 -0
  26. package/dist/middleware/a5-console-logger.middleware.d.ts +9 -0
  27. package/dist/middleware/a5-console-logger.middleware.js +58 -0
  28. package/dist/middleware/index.d.ts +1 -0
  29. package/dist/middleware/index.js +18 -0
  30. package/dist/module/config/index.d.ts +18 -0
  31. package/dist/module/config/index.js +36 -0
  32. package/dist/module/config/interface.d.ts +9 -0
  33. package/dist/module/config/interface.js +15 -0
  34. package/dist/module/index.d.ts +2 -0
  35. package/dist/module/index.js +19 -0
  36. package/dist/module/log/index.d.ts +18 -0
  37. package/dist/module/log/index.js +44 -0
  38. package/dist/module/log/interface.d.ts +9 -0
  39. package/dist/module/log/interface.js +15 -0
  40. package/dist/plugins/index.d.ts +1 -0
  41. package/dist/plugins/index.js +18 -0
  42. package/dist/plugins/nanoid.d.ts +1 -0
  43. package/dist/plugins/nanoid.js +6 -0
  44. package/dist/test/integration/core/a5-factory.integration.spec.d.ts +1 -0
  45. package/dist/test/integration/core/a5-factory.integration.spec.js +99 -0
  46. package/dist/test/integration/core/with-logger-module.integration.spec.d.ts +1 -0
  47. package/dist/test/integration/core/with-logger-module.integration.spec.js +401 -0
  48. package/dist/test/unit/core/a5-application.unit.spec.d.ts +1 -0
  49. package/dist/test/unit/core/a5-application.unit.spec.js +450 -0
  50. package/dist/test/unit/core/a5-console-logger.unit.spec.d.ts +1 -0
  51. package/dist/test/unit/core/a5-console-logger.unit.spec.js +998 -0
  52. package/dist/test/unit/middleware/a5-console-logger.middleware.unit.spec.d.ts +1 -0
  53. package/dist/test/unit/middleware/a5-console-logger.middleware.unit.spec.js +379 -0
  54. package/dist/test/unit/util/a5.util.unit.spec.d.ts +1 -0
  55. package/dist/test/unit/util/a5.util.unit.spec.js +109 -0
  56. package/dist/test/unit/util/color.util.unit.spec.d.ts +1 -0
  57. package/dist/test/unit/util/color.util.unit.spec.js +277 -0
  58. package/dist/test/unit/util/logo.util.unit.spec.d.ts +1 -0
  59. package/dist/test/unit/util/logo.util.unit.spec.js +202 -0
  60. package/dist/test/unit/util/run-env.util.unit.spec.d.ts +1 -0
  61. package/dist/test/unit/util/run-env.util.unit.spec.js +183 -0
  62. package/dist/util/a5.util.d.ts +27 -0
  63. package/dist/util/a5.util.js +41 -0
  64. package/dist/util/color.util.d.ts +26 -0
  65. package/dist/util/color.util.js +62 -0
  66. package/dist/util/index.d.ts +5 -0
  67. package/dist/util/index.js +22 -0
  68. package/dist/util/load-package.util.d.ts +29 -0
  69. package/dist/util/load-package.util.js +71 -0
  70. package/dist/util/logo.util.d.ts +31 -0
  71. package/dist/util/logo.util.js +59 -0
  72. package/dist/util/run-env.util.d.ts +28 -0
  73. package/dist/util/run-env.util.js +48 -0
  74. package/logo +7 -0
  75. package/package.json +96 -0
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1,3 @@
1
+ export * from './base';
2
+ export * from './http';
3
+ export * from './provide-token';
@@ -0,0 +1,20 @@
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("./base"), exports);
18
+ __exportStar(require("./http"), exports);
19
+ __exportStar(require("./provide-token"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @public
3
+ *
4
+ * `A5` 全局提供者 Token。
5
+ *
6
+ */
7
+ export type A5GlobalProvideToken = `Global.A5.${string}`;
8
+ /**
9
+ * @public
10
+ *
11
+ * `A5` 作用域提供者 Token。
12
+ *
13
+ */
14
+ export type A5ScopeProvideToken = `Scope.A5.${string}`;
15
+ /**
16
+ * @public
17
+ *
18
+ * `A5` 配置项路径。
19
+ *
20
+ */
21
+ export type A5ModuleConfigPath = `A5.${string}`;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=provide-token.js.map
@@ -0,0 +1,9 @@
1
+ import { Logger, NestMiddleware } from '@nestjs/common';
2
+ import type { FastifyReplyRaw, FastifyRequestRaw } from '../interface/http';
3
+ /**
4
+ * @public
5
+ */
6
+ export declare class A5ConsoleLoggerMiddleware implements NestMiddleware {
7
+ protected logger: Logger;
8
+ use(req: FastifyRequestRaw, res: FastifyReplyRaw, next: () => void): void;
9
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.A5ConsoleLoggerMiddleware = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ /**
12
+ * @public
13
+ */
14
+ let A5ConsoleLoggerMiddleware = class A5ConsoleLoggerMiddleware {
15
+ constructor() {
16
+ this.logger = new common_1.Logger('HttpRequest');
17
+ }
18
+ use(req, res, next) {
19
+ const { method, headers, httpVersion, socket } = req;
20
+ const st = Date.now();
21
+ let bytes = 0;
22
+ // 保存原始 write 和 end 方法
23
+ const originalWrite = res.write;
24
+ const originalEnd = res.end;
25
+ // eslint-disable-next-line func-names
26
+ res.write = function (chunk, ...args) {
27
+ if (chunk) {
28
+ bytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
29
+ }
30
+ // @ts-ignore
31
+ return originalWrite.apply(this, [chunk, ...args]);
32
+ };
33
+ // eslint-disable-next-line func-names
34
+ res.end = function (chunk, ...args) {
35
+ if (chunk) {
36
+ bytes += Buffer.isBuffer(chunk) ? chunk.length : Buffer.byteLength(chunk);
37
+ }
38
+ // @ts-ignore
39
+ return originalEnd.apply(this, [chunk, ...args]);
40
+ };
41
+ res.on('finish', () => {
42
+ const { statusCode } = res;
43
+ const remoteAddr = socket?.remoteAddress || '-';
44
+ const requestTime = Date.now() - st;
45
+ const referer = headers.referer || '-';
46
+ const userAgent = headers['user-agent'] || '-';
47
+ // Nginx access log 格式
48
+ this.logger.log(`${remoteAddr} - "${method} ${req.url} HTTP/${httpVersion}" ${statusCode} ${bytes} ${requestTime}ms "${referer}" "${userAgent}"`);
49
+ });
50
+ // TODO 如果请求失败了,或各种情况,怎么处理?
51
+ next();
52
+ }
53
+ };
54
+ exports.A5ConsoleLoggerMiddleware = A5ConsoleLoggerMiddleware;
55
+ exports.A5ConsoleLoggerMiddleware = A5ConsoleLoggerMiddleware = __decorate([
56
+ (0, common_1.Injectable)()
57
+ ], A5ConsoleLoggerMiddleware);
58
+ //# sourceMappingURL=a5-console-logger.middleware.js.map
@@ -0,0 +1 @@
1
+ export * from './a5-console-logger.middleware';
@@ -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-console-logger.middleware"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import type { A5GlobalProvideToken } from '../../interface';
2
+ export * from './interface';
3
+ /**
4
+ *
5
+ * @public
6
+ *
7
+ * `A5 Config Module` Config Path
8
+ *
9
+ */
10
+ export declare const MODULE_CONFIG_PATH_A5_CONFIG: <T extends string>(str: T) => `A5.config.${T}`;
11
+ /**
12
+ *
13
+ * @public
14
+ *
15
+ * `A5 Log Module` Global Provide Token
16
+ *
17
+ */
18
+ export declare const GLOBAL_PROVIDE_TOKEN_A5_CONFIG: A5GlobalProvideToken;
@@ -0,0 +1,36 @@
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
+ exports.GLOBAL_PROVIDE_TOKEN_A5_CONFIG = exports.MODULE_CONFIG_PATH_A5_CONFIG = void 0;
18
+ __exportStar(require("./interface"), exports);
19
+ /**
20
+ *
21
+ * @public
22
+ *
23
+ * `A5 Config Module` Config Path
24
+ *
25
+ */
26
+ const MODULE_CONFIG_PATH_A5_CONFIG = (str) => `A5.config.${str}`;
27
+ exports.MODULE_CONFIG_PATH_A5_CONFIG = MODULE_CONFIG_PATH_A5_CONFIG;
28
+ /**
29
+ *
30
+ * @public
31
+ *
32
+ * `A5 Log Module` Global Provide Token
33
+ *
34
+ */
35
+ exports.GLOBAL_PROVIDE_TOKEN_A5_CONFIG = 'Global.A5.Config';
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @public
4
+ *
5
+ * `A5 Config Module` 抽象类。
6
+ *
7
+ */
8
+ export declare abstract class IA5ConfigModule {
9
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // import { LoggerService } from '@nestjs/common'
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.IA5ConfigModule = void 0;
5
+ /**
6
+ *
7
+ * @public
8
+ *
9
+ * `A5 Config Module` 抽象类。
10
+ *
11
+ */
12
+ class IA5ConfigModule {
13
+ }
14
+ exports.IA5ConfigModule = IA5ConfigModule;
15
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1,2 @@
1
+ export * from './config';
2
+ export * from './log';
@@ -0,0 +1,19 @@
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("./config"), exports);
18
+ __exportStar(require("./log"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import type { A5GlobalProvideToken } from '../../interface';
2
+ export * from './interface';
3
+ /**
4
+ *
5
+ * @public
6
+ *
7
+ * `A5 Log Module` Config Path
8
+ *
9
+ */
10
+ export declare const MODULE_CONFIG_PATH_A5_LOG: <T extends string>(str: T) => `A5.log.${T}`;
11
+ /**
12
+ *
13
+ * @public
14
+ *
15
+ * `A5 Log Module` Global Provide Token
16
+ *
17
+ */
18
+ export declare const GLOBAL_PROVIDE_TOKEN_A5_LOG_LOGGER: A5GlobalProvideToken;
@@ -0,0 +1,44 @@
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
+ exports.GLOBAL_PROVIDE_TOKEN_A5_LOG_LOGGER = exports.MODULE_CONFIG_PATH_A5_LOG = void 0;
18
+ __exportStar(require("./interface"), exports);
19
+ /**
20
+ *
21
+ * @public
22
+ *
23
+ * `A5 Log Module` Config Path
24
+ *
25
+ */
26
+ const MODULE_CONFIG_PATH_A5_LOG = (str) => `A5.log.${str}`;
27
+ exports.MODULE_CONFIG_PATH_A5_LOG = MODULE_CONFIG_PATH_A5_LOG;
28
+ /**
29
+ *
30
+ * @public
31
+ *
32
+ * `A5 Log Module` Global Provide Token
33
+ *
34
+ */
35
+ exports.GLOBAL_PROVIDE_TOKEN_A5_LOG_LOGGER = 'Global.A5.Log.Logger';
36
+ // /**
37
+ // *
38
+ // * @public
39
+ // *
40
+ // * `A5 Log Module` Scope Provide Token
41
+ // *
42
+ // */
43
+ // export const SCOPE_PROVIDE_TOKEN_A5_LOGGER: A5ScopeProvideToken = 'Scope.A5.Log'
44
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @public
4
+ *
5
+ * `A5 Log Module` 抽象类。
6
+ *
7
+ */
8
+ export declare abstract class IA5LogModule {
9
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // import { LoggerService } from '@nestjs/common'
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.IA5LogModule = void 0;
5
+ /**
6
+ *
7
+ * @public
8
+ *
9
+ * `A5 Log Module` 抽象类。
10
+ *
11
+ */
12
+ class IA5LogModule {
13
+ }
14
+ exports.IA5LogModule = IA5LogModule;
15
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ export * from './nanoid';
@@ -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("./nanoid"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ export { nanoid } from 'nanoid';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nanoid = void 0;
4
+ var nanoid_1 = require("nanoid");
5
+ Object.defineProperty(exports, "nanoid", { enumerable: true, get: function () { return nanoid_1.nanoid; } });
6
+ //# sourceMappingURL=nanoid.js.map
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ /* eslint-disable @typescript-eslint/consistent-type-definitions */
13
+ const core_1 = require("../../../core");
14
+ const util_1 = require("../../../util");
15
+ const node_console_1 = __importDefault(require("node:console"));
16
+ const common_1 = require("@nestjs/common");
17
+ describe('A5Factory', () => {
18
+ describe('create', () => {
19
+ describe('printLogo', () => {
20
+ const toClearLines = (lines) => lines.map(([text]) => util_1.ColorUtil.clear(text));
21
+ let logoLines = [];
22
+ beforeAll(async () => {
23
+ const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
24
+ util_1.LogoUtil.print();
25
+ // 验证完整的日志输出格式(移除 ANSI 颜色代码后验证)
26
+ logoLines = toClearLines(logSpy.mock.calls);
27
+ logSpy.mockRestore();
28
+ });
29
+ it('default', async () => {
30
+ const logSpy = jest.spyOn(process.stdout, 'write').mockImplementation();
31
+ let AppModule = class AppModule {
32
+ };
33
+ AppModule = __decorate([
34
+ (0, common_1.Module)({})
35
+ ], AppModule);
36
+ const app = await core_1.A5Factory.create(AppModule);
37
+ expect(app.options.logger).toBeInstanceOf(core_1.A5ConsoleLogger);
38
+ await app.close();
39
+ // 验证完整的日志输出格式(移除 ANSI 颜色代码后验证)
40
+ const lines = toClearLines(logSpy.mock.calls);
41
+ logSpy.mockRestore();
42
+ // lines[0]
43
+ expect(lines.length).toBe(7);
44
+ expect(lines[0].replace(/\n$/, '')).toBe(logoLines[0]);
45
+ expect(lines[1].replace(/\n$/, '')).toBe(logoLines[1]);
46
+ expect(lines[2].replace(/\n$/, '')).toBe(logoLines[2]);
47
+ expect(lines[3].trimEnd()).toMatch(/WARN \[A5Application \] Not loaded A5 Logger Provider, using 'A5ConsoleLogger'$/);
48
+ expect(lines[4].trimEnd()).toMatch(/ LOG \[A5Factory \] Starting A5 application...$/);
49
+ expect(lines[5].trimEnd()).toMatch(/ LOG \[InstanceLoader\] AppModule dependencies initialized$/);
50
+ expect(lines[6].trimEnd()).toMatch(/ LOG \[A5Application \] A5 application successfully started$/);
51
+ });
52
+ it('true', async () => {
53
+ const logSpy = jest.spyOn(process.stdout, 'write').mockImplementation();
54
+ let AppModule = class AppModule {
55
+ };
56
+ AppModule = __decorate([
57
+ (0, common_1.Module)({})
58
+ ], AppModule);
59
+ const app = await core_1.A5Factory.create(AppModule, { printLogo: true });
60
+ expect(app.options.logger).toBeInstanceOf(core_1.A5ConsoleLogger);
61
+ await app.close();
62
+ // 验证完整的日志输出格式(移除 ANSI 颜色代码后验证)
63
+ const lines = toClearLines(logSpy.mock.calls);
64
+ logSpy.mockRestore();
65
+ // lines[0]
66
+ expect(lines.length).toBe(7);
67
+ expect(lines[0].replace(/\n$/, '')).toBe(logoLines[0]);
68
+ expect(lines[1].replace(/\n$/, '')).toBe(logoLines[1]);
69
+ expect(lines[2].replace(/\n$/, '')).toBe(logoLines[2]);
70
+ expect(lines[3].trimEnd()).toMatch(/WARN \[A5Application \] Not loaded A5 Logger Provider, using 'A5ConsoleLogger'$/);
71
+ expect(lines[4].trimEnd()).toMatch(/ LOG \[A5Factory \] Starting A5 application...$/);
72
+ expect(lines[5].trimEnd()).toMatch(/ LOG \[InstanceLoader\] AppModule dependencies initialized$/);
73
+ expect(lines[6].trimEnd()).toMatch(/ LOG \[A5Application \] A5 application successfully started$/);
74
+ });
75
+ it('false', async () => {
76
+ const logSpy = jest.spyOn(process.stdout, 'write').mockImplementation();
77
+ let AppModule = class AppModule {
78
+ };
79
+ AppModule = __decorate([
80
+ (0, common_1.Module)({})
81
+ ], AppModule);
82
+ const app = await core_1.A5Factory.create(AppModule, {
83
+ printLogo: false,
84
+ });
85
+ expect(app.options.logger).toBeInstanceOf(core_1.A5ConsoleLogger);
86
+ await app.close();
87
+ // 验证完整的日志输出格式(移除 ANSI 颜色代码后验证)
88
+ const lines = toClearLines(logSpy.mock.calls);
89
+ logSpy.mockRestore();
90
+ expect(lines.length).toBe(4);
91
+ expect(lines[0].trimEnd()).toMatch(/WARN \[A5Application \] Not loaded A5 Logger Provider, using 'A5ConsoleLogger'$/);
92
+ expect(lines[1].trimEnd()).toMatch(/ LOG \[A5Factory \] Starting A5 application...$/);
93
+ expect(lines[2].trimEnd()).toMatch(/ LOG \[InstanceLoader\] AppModule dependencies initialized$/);
94
+ expect(lines[3].trimEnd()).toMatch(/ LOG \[A5Application \] A5 application successfully started$/);
95
+ });
96
+ });
97
+ });
98
+ });
99
+ //# sourceMappingURL=a5-factory.integration.spec.js.map