@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,163 @@
1
+ import './__import-reflect-metadata';
2
+ import { LogLevel, LoggerService } from '@nestjs/common/services/logger.service';
3
+ /**
4
+ * @public
5
+ */
6
+ export declare const DEFAULT_LOG_LEVELS: LogLevel[];
7
+ /**
8
+ * @public
9
+ */
10
+ export interface A5ConsoleLoggerConstructorOptions {
11
+ /**
12
+ * Context name for logs
13
+ *
14
+ * Default is ''
15
+ */
16
+ context?: string;
17
+ /**
18
+ * Enabled log levels.
19
+ *
20
+ * Default is @see DEFAULT_LOG_LEVELS
21
+ */
22
+ logLevels?: LogLevel[];
23
+ /**
24
+ * If enabled, will print timestamp (time difference) between current and previous log message.
25
+ *
26
+ * Default is `false`
27
+ */
28
+ timestamp?: boolean;
29
+ }
30
+ /**
31
+ * @public
32
+ */
33
+ export type A5ConsoleLoggerOptions = Omit<Required<A5ConsoleLoggerConstructorOptions>, 'context'>;
34
+ interface A5FormatMessageOptions {
35
+ logLevel: LogLevel;
36
+ context: string;
37
+ message: unknown;
38
+ }
39
+ /**
40
+ * @public
41
+ */
42
+ export interface A5FormatMessageInfo {
43
+ prefix: string;
44
+ pid: string;
45
+ timestamp: number;
46
+ timestampStr: string;
47
+ logLevel: string;
48
+ context: string;
49
+ output: string;
50
+ timestampDiff: number | null;
51
+ timestampDiffStr: string;
52
+ }
53
+ /**
54
+ * @public
55
+ */
56
+ export declare class A5ConsoleLogger implements LoggerService {
57
+ protected static lastTimestampAt?: number;
58
+ protected readonly originalContext: string;
59
+ protected context: string;
60
+ protected options: A5ConsoleLoggerOptions;
61
+ constructor(options?: A5ConsoleLoggerConstructorOptions);
62
+ /**
63
+ * Write a 'log' level log, if the configured level allows for it.
64
+ * Prints to `stdout` with newline.
65
+ */
66
+ log(message: unknown, context?: string): void;
67
+ log(message: unknown, ...optionalParams: [...unknown[], string | unknown]): void;
68
+ /**
69
+ * Write an 'error' level log, if the configured level allows for it.
70
+ * Prints to `stderr` with newline.
71
+ */
72
+ error(message: unknown, stackOrContext?: string): void;
73
+ error(message: unknown, stack?: string, context?: string): void;
74
+ error(message: unknown, ...optionalParams: [...unknown[], string | unknown, string | unknown]): void;
75
+ /**
76
+ * Write a 'warn' level log, if the configured level allows for it.
77
+ * Prints to `stdout` with newline.
78
+ */
79
+ warn(message: unknown, context?: string): void;
80
+ warn(message: unknown, ...optionalParams: [...unknown[], string | unknown]): void;
81
+ /**
82
+ * Write a 'debug' level log, if the configured level allows for it.
83
+ * Prints to `stdout` with newline.
84
+ */
85
+ debug(message: unknown, context?: string): void;
86
+ debug(message: unknown, ...optionalParams: [...unknown[], string | unknown]): void;
87
+ /**
88
+ * Write a 'verbose' level log, if the configured level allows for it.
89
+ * Prints to `stdout` with newline.
90
+ */
91
+ verbose(message: unknown, context?: string): void;
92
+ verbose(message: unknown, ...optionalParams: [...unknown[], string | unknown]): void;
93
+ /**
94
+ * TODO 需要思考,是否需要让 fatal 与 error 保持一致!!!
95
+ */
96
+ /**
97
+ * Write a 'fatal' level log, if the configured level allows for it.
98
+ * Prints to `stdout` with newline.
99
+ */
100
+ fatal(message: unknown, context?: string): void;
101
+ fatal(message: unknown, ...optionalParams: [...unknown[], string | unknown]): void;
102
+ /**
103
+ * Set log levels
104
+ * @param levels - log levels
105
+ */
106
+ setLogLevels(levels: LogLevel[]): void;
107
+ /**
108
+ * Set logger context
109
+ * @param context - context
110
+ */
111
+ setContext(context: string): void;
112
+ /**
113
+ * Get logger context
114
+ * @param context - context
115
+ */
116
+ getContext(): string;
117
+ /**
118
+ * Resets the logger context to the value that was passed in the constructor.
119
+ */
120
+ resetContext(): void;
121
+ isLevelEnabled(level: LogLevel): boolean;
122
+ protected printMessages(messages: unknown[], context_: string, logLevel?: LogLevel, writeStreamType?: 'stdout' | 'stderr'): void;
123
+ protected formatMessage(options: A5FormatMessageOptions): string;
124
+ protected formatMessageStructure(options: A5FormatMessageOptions): A5FormatMessageInfo;
125
+ protected formatPrefix(): string;
126
+ protected formatPid(): string;
127
+ protected formatLogLevel(logLevel: LogLevel): string;
128
+ protected formatTimestamp(dateMilliseconds: number): string;
129
+ protected formatContext(context: string): string;
130
+ protected stringifyMessage(message: unknown, logLevel: LogLevel): string;
131
+ protected colorize(message: string, logLevel: LogLevel): string;
132
+ protected printStackTrace(stack: string | undefined): void;
133
+ protected updateAndGetTimestampDiff(): number | null;
134
+ protected formatTimestampDiff(timestampDiff: number | null): string;
135
+ protected getContextAndMessagesToPrint(args: unknown[]): {
136
+ context: string;
137
+ messages: unknown[];
138
+ };
139
+ protected getContextAndStackAndMessagesToPrint(args: unknown[]): {
140
+ messages: unknown[];
141
+ context: string;
142
+ stack?: string;
143
+ };
144
+ protected isStackFormat(stack: unknown): stack is string;
145
+ /**
146
+ * 移除最后 多个 undefined
147
+ */
148
+ protected removeLastUndefined(args: unknown[]): unknown[];
149
+ protected getColorByLogLevel(level: LogLevel): (text: string) => string;
150
+ /**
151
+ * 保证日志数据的统一格式,对 Nest 默认的日志输出进行格式化。
152
+ */
153
+ protected _contextNeedApologeticReplace(context: string): context is 'NestFactory' | 'NestApplication';
154
+ /**
155
+ * 保证日志数据的统一格式,对 Nest 默认的日志输出进行格式化。
156
+ */
157
+ protected _contextApologeticReplace(context: 'NestFactory' | 'NestApplication'): string;
158
+ /**
159
+ * 保证日志数据的统一格式,对 Nest 默认的日志输出进行格式化。
160
+ */
161
+ protected _messageApologeticReplace(message: unknown): unknown;
162
+ }
163
+ export {};
@@ -0,0 +1,354 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var A5ConsoleLogger_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.A5ConsoleLogger = exports.DEFAULT_LOG_LEVELS = void 0;
17
+ require("./__import-reflect-metadata");
18
+ const injectable_decorator_1 = require("@nestjs/common/decorators/core/injectable.decorator");
19
+ const optional_decorator_1 = require("@nestjs/common/decorators/core/optional.decorator");
20
+ const is_log_level_enabled_util_1 = require("@nestjs/common/services/utils/is-log-level-enabled.util");
21
+ const cli_colors_util_1 = require("@nestjs/common/utils/cli-colors.util");
22
+ const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
23
+ /**
24
+ * @public
25
+ */
26
+ 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
+ /**
37
+ * @public
38
+ */
39
+ let A5ConsoleLogger = A5ConsoleLogger_1 = class A5ConsoleLogger {
40
+ constructor(options = {}) {
41
+ this.originalContext = '';
42
+ this.context = '';
43
+ this.options = {
44
+ logLevels: Array.isArray(options.logLevels) ? options.logLevels : exports.DEFAULT_LOG_LEVELS,
45
+ timestamp: typeof options.timestamp === 'boolean' ? options.timestamp : false,
46
+ };
47
+ this.originalContext = options.context ?? '';
48
+ this.context = options.context ?? '';
49
+ }
50
+ log(message, ...optionalParams) {
51
+ if (!this.isLevelEnabled('log')) {
52
+ return;
53
+ }
54
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
55
+ this.printMessages(messages, context, 'log');
56
+ }
57
+ error(message, ...optionalParams) {
58
+ if (!this.isLevelEnabled('error')) {
59
+ return;
60
+ }
61
+ const { messages, context, stack } = this.getContextAndStackAndMessagesToPrint([message, ...optionalParams]);
62
+ this.printMessages(messages, context, 'error', 'stderr');
63
+ this.printStackTrace(stack);
64
+ }
65
+ warn(message, ...optionalParams) {
66
+ if (!this.isLevelEnabled('warn')) {
67
+ return;
68
+ }
69
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
70
+ this.printMessages(messages, context, 'warn');
71
+ }
72
+ debug(message, ...optionalParams) {
73
+ if (!this.isLevelEnabled('debug')) {
74
+ return;
75
+ }
76
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
77
+ this.printMessages(messages, context, 'debug');
78
+ }
79
+ verbose(message, ...optionalParams) {
80
+ if (!this.isLevelEnabled('verbose')) {
81
+ return;
82
+ }
83
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
84
+ this.printMessages(messages, context, 'verbose');
85
+ }
86
+ fatal(message, ...optionalParams) {
87
+ if (!this.isLevelEnabled('fatal')) {
88
+ return;
89
+ }
90
+ const { messages, context } = this.getContextAndMessagesToPrint([message, ...optionalParams]);
91
+ this.printMessages(messages, context, 'fatal');
92
+ }
93
+ /**
94
+ * Set log levels
95
+ * @param levels - log levels
96
+ */
97
+ setLogLevels(levels) {
98
+ this.options.logLevels = levels;
99
+ }
100
+ /**
101
+ * Set logger context
102
+ * @param context - context
103
+ */
104
+ setContext(context) {
105
+ this.context = context;
106
+ }
107
+ /**
108
+ * Get logger context
109
+ * @param context - context
110
+ */
111
+ getContext() {
112
+ return this.context;
113
+ }
114
+ /**
115
+ * Resets the logger context to the value that was passed in the constructor.
116
+ */
117
+ resetContext() {
118
+ this.context = this.originalContext;
119
+ }
120
+ isLevelEnabled(level) {
121
+ const logLevels = this.options?.logLevels;
122
+ return (0, is_log_level_enabled_util_1.isLogLevelEnabled)(level, logLevels);
123
+ }
124
+ printMessages(messages, context_, logLevel = 'log', writeStreamType) {
125
+ messages.forEach((message_) => {
126
+ let context = context_;
127
+ let message = message_;
128
+ /**
129
+ * 在此处,会对 NestFactory 及 NestApplication 相关日志输出进行重写。
130
+ */
131
+ if (this._contextNeedApologeticReplace(context)) {
132
+ context = this._contextApologeticReplace(context);
133
+ message = this._messageApologeticReplace(message);
134
+ }
135
+ const formattedMessage = this.formatMessage({
136
+ logLevel,
137
+ context,
138
+ message,
139
+ });
140
+ process[writeStreamType ?? 'stdout'].write(formattedMessage);
141
+ });
142
+ }
143
+ formatMessage(options) {
144
+ const { prefix, pid, timestampStr, logLevel, context, output, timestampDiffStr } = this.formatMessageStructure(options);
145
+ let message = `${prefix} ${pid} - ${timestampStr} ${this.colorize(logLevel, options.logLevel)}`;
146
+ if (context) {
147
+ message += ` ${cli_colors_util_1.clc.yellow(context)}`;
148
+ }
149
+ message += ` ${output}`;
150
+ if (timestampDiffStr) {
151
+ message += ` ${cli_colors_util_1.clc.yellow(timestampDiffStr)}`;
152
+ }
153
+ message += '\n';
154
+ return message;
155
+ }
156
+ formatMessageStructure(options) {
157
+ const prefix = this.formatPrefix();
158
+ const pid = this.formatPid();
159
+ const timestamp = Date.now();
160
+ const timestampStr = this.formatTimestamp(timestamp);
161
+ const logLevel = this.formatLogLevel(options.logLevel);
162
+ const context = this.formatContext(options.context);
163
+ const output = this.stringifyMessage(options.message, options.logLevel);
164
+ const timestampDiff = this.updateAndGetTimestampDiff();
165
+ const timestampDiffStr = this.formatTimestampDiff(timestampDiff);
166
+ return {
167
+ prefix,
168
+ pid,
169
+ timestamp,
170
+ timestampStr,
171
+ logLevel,
172
+ context,
173
+ output,
174
+ timestampDiff,
175
+ timestampDiffStr,
176
+ };
177
+ }
178
+ formatPrefix() {
179
+ return `[A5]`;
180
+ }
181
+ formatPid() {
182
+ return process.pid.toString().padEnd(6, ' ');
183
+ }
184
+ formatLogLevel(logLevel) {
185
+ return logLevel.toUpperCase().padStart(7, ' ');
186
+ }
187
+ formatTimestamp(dateMilliseconds) {
188
+ return dateTimeFormatter.format(dateMilliseconds).replace(/ /g, 'T').replace(/\//g, '-');
189
+ }
190
+ formatContext(context) {
191
+ if (context.length === 0)
192
+ return '';
193
+ const context_ = context.length > 14 ? context.slice(0, 14) : context.padEnd(14, ' ');
194
+ return `[${context_}]`;
195
+ }
196
+ stringifyMessage(message, logLevel) {
197
+ if ((0, shared_utils_1.isFunction)(message)) {
198
+ const messageAsStr = Function.prototype.toString.call(message);
199
+ const isClass = messageAsStr.startsWith('class ');
200
+ if (isClass) {
201
+ // If the message is a class, we will display the class name.
202
+ return this.stringifyMessage(message.name, logLevel);
203
+ }
204
+ // If the message is a non-class function, call it and re-resolve its value.
205
+ return this.stringifyMessage(message(), logLevel);
206
+ }
207
+ return (0, shared_utils_1.isPlainObject)(message) || Array.isArray(message)
208
+ ? `${this.colorize('Object:', logLevel)}\n${JSON.stringify(message, (key, value) => (typeof value === 'bigint' ? value.toString() : value), 2)}\n`
209
+ : this.colorize(message, logLevel);
210
+ }
211
+ colorize(message, logLevel) {
212
+ const color = this.getColorByLogLevel(logLevel);
213
+ return color(message);
214
+ }
215
+ printStackTrace(stack) {
216
+ if (!stack) {
217
+ return;
218
+ }
219
+ process.stderr.write(`${stack}\n`);
220
+ }
221
+ updateAndGetTimestampDiff() {
222
+ let result = null;
223
+ const now = Date.now();
224
+ if (this.options?.timestamp) {
225
+ if (!A5ConsoleLogger_1.lastTimestampAt) {
226
+ /**
227
+ * 第一次调用时,初始化 A5ConsoleLogger.lastTimestampAt
228
+ */
229
+ A5ConsoleLogger_1.lastTimestampAt = now;
230
+ }
231
+ result = now - A5ConsoleLogger_1.lastTimestampAt;
232
+ }
233
+ A5ConsoleLogger_1.lastTimestampAt = now;
234
+ return result;
235
+ }
236
+ formatTimestampDiff(timestampDiff) {
237
+ return timestampDiff !== null ? `+${timestampDiff}ms` : '';
238
+ }
239
+ getContextAndMessagesToPrint(args) {
240
+ if (args?.length <= 1) {
241
+ return { context: this.context, messages: args };
242
+ }
243
+ const lastElement = args[args.length - 1];
244
+ if (typeof lastElement === 'string') {
245
+ return {
246
+ context: lastElement,
247
+ messages: args.slice(0, args.length - 1),
248
+ };
249
+ }
250
+ return { context: this.context, messages: args };
251
+ }
252
+ getContextAndStackAndMessagesToPrint(args) {
253
+ if (args.length === 2) {
254
+ return this.isStackFormat(args[1])
255
+ ? {
256
+ context: this.context,
257
+ messages: [args[0]],
258
+ stack: args[1],
259
+ }
260
+ : {
261
+ context: args[1],
262
+ messages: [args[0]],
263
+ };
264
+ }
265
+ const { context, messages } = this.getContextAndMessagesToPrint(args);
266
+ if (messages?.length <= 1) {
267
+ return {
268
+ context,
269
+ messages: this.removeLastUndefined(messages),
270
+ };
271
+ }
272
+ const lastElement = messages[messages.length - 1];
273
+ if (this.isStackFormat(lastElement)) {
274
+ return {
275
+ context,
276
+ messages: this.removeLastUndefined(messages.slice(0, messages.length - 1)),
277
+ stack: lastElement,
278
+ };
279
+ }
280
+ return {
281
+ context,
282
+ messages: this.removeLastUndefined(messages),
283
+ };
284
+ }
285
+ isStackFormat(stack) {
286
+ return (0, shared_utils_1.isString)(stack) && /^(.)+\n\s+at .+:\d+:\d+/.test(stack);
287
+ }
288
+ /**
289
+ * 移除最后 多个 undefined
290
+ */
291
+ removeLastUndefined(args) {
292
+ // 从末尾开始查找第一个非 undefined 元素的索引
293
+ let lastIndex = args.length - 1;
294
+ while (lastIndex >= 0 && args[lastIndex] === undefined) {
295
+ lastIndex -= 1;
296
+ }
297
+ // // 如果所有元素都是 undefined,返回空数组
298
+ // if (lastIndex < 0) {
299
+ // return []
300
+ // }
301
+ // 返回截取后的数组
302
+ return args.slice(0, lastIndex + 1);
303
+ }
304
+ getColorByLogLevel(level) {
305
+ switch (level) {
306
+ case 'debug':
307
+ return cli_colors_util_1.clc.magentaBright;
308
+ case 'warn':
309
+ return cli_colors_util_1.clc.yellow;
310
+ case 'error':
311
+ return cli_colors_util_1.clc.red;
312
+ case 'verbose':
313
+ return cli_colors_util_1.clc.cyanBright;
314
+ case 'fatal':
315
+ return cli_colors_util_1.clc.bold;
316
+ default:
317
+ return cli_colors_util_1.clc.green;
318
+ }
319
+ }
320
+ /**
321
+ * 保证日志数据的统一格式,对 Nest 默认的日志输出进行格式化。
322
+ */
323
+ _contextNeedApologeticReplace(context) {
324
+ return ['NestFactory', 'NestApplication'].includes(context);
325
+ }
326
+ /**
327
+ * 保证日志数据的统一格式,对 Nest 默认的日志输出进行格式化。
328
+ */
329
+ _contextApologeticReplace(context) {
330
+ return {
331
+ NestFactory: 'A5Factory',
332
+ NestApplication: 'A5Application',
333
+ }[context];
334
+ }
335
+ /**
336
+ * 保证日志数据的统一格式,对 Nest 默认的日志输出进行格式化。
337
+ */
338
+ _messageApologeticReplace(message) {
339
+ return typeof message === 'string'
340
+ ? ({
341
+ 'Starting Nest application...': 'Starting A5 application...',
342
+ 'Nest application successfully started': 'A5 application successfully started',
343
+ 'Nest microservice successfully started': 'A5 microservice successfully started',
344
+ }[message] ?? message)
345
+ : message;
346
+ }
347
+ };
348
+ exports.A5ConsoleLogger = A5ConsoleLogger;
349
+ exports.A5ConsoleLogger = A5ConsoleLogger = A5ConsoleLogger_1 = __decorate([
350
+ (0, injectable_decorator_1.Injectable)(),
351
+ __param(0, (0, optional_decorator_1.Optional)()),
352
+ __metadata("design:paramtypes", [Object])
353
+ ], A5ConsoleLogger);
354
+ //# sourceMappingURL=a5-console-logger.js.map
@@ -0,0 +1,21 @@
1
+ import { NestFactoryStatic } from '@nestjs/core/nest-factory';
2
+ import { A5Application } from './a5-application';
3
+ /**
4
+ * @public
5
+ */
6
+ export interface A5FactoryCreateOptions {
7
+ /**
8
+ * 是否输出日志信息。可选。默认为 true
9
+ */
10
+ readonly printLogo?: boolean;
11
+ }
12
+ declare class A5FactoryStatic {
13
+ protected nestFactoryStatic: NestFactoryStatic;
14
+ constructor();
15
+ create(module: unknown, options?: A5FactoryCreateOptions): Promise<A5Application>;
16
+ }
17
+ /**
18
+ * @public
19
+ */
20
+ export declare const A5Factory: A5FactoryStatic;
21
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.A5Factory = void 0;
4
+ const nest_factory_1 = require("@nestjs/core/nest-factory");
5
+ const platform_fastify_1 = require("@nestjs/platform-fastify");
6
+ const util_1 = require("../util");
7
+ const a5_application_1 = require("./a5-application");
8
+ class A5FactoryStatic {
9
+ // ...
10
+ // protected static initBodyParser(nestApplication: NestApplication, options: IA5FactoryInitBodyParserOptions): void {
11
+ // if (options.bodyParser ?? true) {
12
+ // nestApplication.useBodyParser('json', {
13
+ // prefix: options.bodyParserPrefix,
14
+ // limit: options.bodyParserLimit ?? '100kb',
15
+ // })
16
+ // nestApplication.useBodyParser('urlencoded', {
17
+ // prefix: options?.bodyParserPrefix,
18
+ // limit: options?.bodyParserLimit ?? '100kb',
19
+ // extended: false,
20
+ // })
21
+ // }
22
+ // }
23
+ constructor() {
24
+ this.nestFactoryStatic = new nest_factory_1.NestFactoryStatic();
25
+ }
26
+ async create(module, options = {}) {
27
+ if (options.printLogo ?? true)
28
+ util_1.LogoUtil.print();
29
+ // const nestOptions: NestApplicationOptions = {
30
+ // ...options,
31
+ // // bodyParser: false,
32
+ // bodyParser: true,
33
+ // bufferLogs: options.bufferLogs ?? true,
34
+ // }
35
+ const nestOptions = {
36
+ bufferLogs: true,
37
+ };
38
+ const nestApplication = await this.nestFactoryStatic.create(module, new platform_fastify_1.FastifyAdapter(), nestOptions);
39
+ // this.initBodyParser(nestApplication, options)
40
+ const app = new a5_application_1.A5Application(nestApplication);
41
+ await app.init();
42
+ return app;
43
+ }
44
+ }
45
+ /**
46
+ * @public
47
+ */
48
+ exports.A5Factory = new A5FactoryStatic();
49
+ //# sourceMappingURL=a5-factory.js.map
@@ -0,0 +1,3 @@
1
+ export * from './a5-console-logger';
2
+ export * from './a5-application';
3
+ export * from './a5-factory';
@@ -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("./a5-console-logger"), exports);
18
+ __exportStar(require("./a5-application"), exports);
19
+ __exportStar(require("./a5-factory"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ export * from './const';
2
+ export * from './core';
3
+ export * from './interface';
4
+ export * from './module';
5
+ export * from './middleware';
6
+ export * from './plugins';
7
+ export * from './util';
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
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("./const"), exports);
18
+ __exportStar(require("./core"), exports);
19
+ __exportStar(require("./interface"), exports);
20
+ __exportStar(require("./module"), exports);
21
+ __exportStar(require("./middleware"), exports);
22
+ __exportStar(require("./plugins"), exports);
23
+ __exportStar(require("./util"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export type Writable<T> = {
5
+ -readonly [P in keyof T]: T[P];
6
+ };
7
+ /**
8
+ * @public
9
+ */
10
+ export type WritableRequired<T> = Writable<Required<T>>;
11
+ /**
12
+ * @public
13
+ */
14
+ export type RequiredButOmit<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
15
+ /**
16
+ * @public
17
+ */
18
+ export type RequiredButPick<T, K extends keyof T> = Required<Omit<T, K>> & Pick<T, K>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @public
3
+ */
4
+ export type FastifyRequestRaw = import('fastify').FastifyRequest['raw'];
5
+ /**
6
+ * @public
7
+ */
8
+ export type FastifyReplyRaw = import('fastify').FastifyReply['raw'];
9
+ /**
10
+ * @public
11
+ */
12
+ export type FastifyReply = import('fastify').FastifyReply;
13
+ /**
14
+ * @public
15
+ */
16
+ export type FastifyRequest = import('fastify').FastifyRequest;