@tstdl/base 0.93.0 → 0.93.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.
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CancellationSignal } from '../cancellation/token.js';
|
|
2
2
|
import { type ProvidersItem } from '../injector/injector.js';
|
|
3
|
-
import type { Resolvable, resolveArgumentType } from '../injector/interfaces.js';
|
|
4
|
-
import type { LoggerArgument } from '../logger/index.js';
|
|
5
3
|
import { Module } from '../module/index.js';
|
|
6
4
|
import type { OneOrMany, Type } from '../types/index.js';
|
|
7
5
|
export type InitializerFn = () => void | Promise<void>;
|
|
@@ -9,10 +7,8 @@ export type DestructorFn = () => void | Promise<void>;
|
|
|
9
7
|
export declare const APPLICATION_MODULE: import("../injector/token.js").InjectionToken<Module, never>;
|
|
10
8
|
export declare const APPLICATION_INITIALIZER: import("../injector/token.js").InjectionToken<InitializerFn, never>;
|
|
11
9
|
export declare const APPLICATION_DESTRUCTOR: import("../injector/token.js").InjectionToken<DestructorFn, never>;
|
|
12
|
-
export
|
|
13
|
-
export declare class Application implements Resolvable<ApplicationArgument> {
|
|
10
|
+
export declare class Application {
|
|
14
11
|
#private;
|
|
15
|
-
readonly [resolveArgumentType]: string;
|
|
16
12
|
static create(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
|
|
17
13
|
static run(name: string, providers?: OneOrMany<ProvidersItem>[]): Application;
|
|
18
14
|
get shutdownSignal(): CancellationSignal;
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var Application_1;
|
|
8
8
|
import { CancellationSignal, CancellationToken } from '../cancellation/token.js';
|
|
9
9
|
import { Singleton } from '../injector/decorators.js';
|
|
10
|
-
import { inject, injectAll,
|
|
10
|
+
import { inject, injectAll, runInInjectionContext } from '../injector/inject.js';
|
|
11
11
|
import { Injector } from '../injector/injector.js';
|
|
12
12
|
import { injectionToken } from '../injector/token.js';
|
|
13
13
|
import { Logger } from '../logger/index.js';
|
|
@@ -19,8 +19,9 @@ import { isDefined, isFunction } from '../utils/type-guards.js';
|
|
|
19
19
|
export const APPLICATION_MODULE = injectionToken('ApplicationModule');
|
|
20
20
|
export const APPLICATION_INITIALIZER = injectionToken('ApplicationInitializer');
|
|
21
21
|
export const APPLICATION_DESTRUCTOR = injectionToken('ApplicationDestructor');
|
|
22
|
+
const APPLICATION_NAME = injectionToken('ApplicationName');
|
|
22
23
|
let Application = Application_1 = class Application {
|
|
23
|
-
#name =
|
|
24
|
+
#name = inject(APPLICATION_NAME);
|
|
24
25
|
#injector = inject(Injector);
|
|
25
26
|
#logger = inject(Logger, this.#name);
|
|
26
27
|
#moduleTypesAndInstances = new Set(injectAll(APPLICATION_MODULE, undefined, { optional: true }));
|
|
@@ -28,10 +29,11 @@ let Application = Application_1 = class Application {
|
|
|
28
29
|
#shutdownToken = inject(CancellationSignal, undefined, { optional: true })?.createChild() ?? new CancellationToken();
|
|
29
30
|
static create(name, providers = []) {
|
|
30
31
|
const injector = new Injector(`${name}Injector`);
|
|
32
|
+
injector.register(APPLICATION_NAME, { useValue: name });
|
|
31
33
|
for (const providersItem of providers.flat()) {
|
|
32
34
|
injector.register(providersItem.provide, providersItem, { multi: providersItem.multi });
|
|
33
35
|
}
|
|
34
|
-
return injector.resolve(Application_1
|
|
36
|
+
return injector.resolve(Application_1);
|
|
35
37
|
}
|
|
36
38
|
static run(name, providers = []) {
|
|
37
39
|
const app = Application_1.create(name, providers);
|
|
@@ -5,21 +5,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Singleton } from '../../injector/decorators.js';
|
|
8
|
+
import { supportsColoredStdout } from '../../supports.js';
|
|
8
9
|
import { enumValueName } from '../../utils/enum.js';
|
|
9
10
|
import { formatError } from '../../utils/format-error.js';
|
|
10
11
|
import { isNotNullOrUndefined } from '../../utils/type-guards.js';
|
|
11
12
|
import { LogFormatter } from '../formatter.js';
|
|
12
13
|
import { LogLevel } from '../level.js';
|
|
13
14
|
const levelColorMap = {
|
|
14
|
-
[LogLevel.Error]: '\x1b[31m', // Red
|
|
15
|
-
[LogLevel.Warn]: '\x1b[33m', // Yellow
|
|
16
|
-
[LogLevel.Info]: '\x1b[32m', // Green
|
|
17
|
-
[LogLevel.Verbose]: '\x1b[36m', // Cyan
|
|
18
|
-
[LogLevel.Debug]: '\x1b[34m', // Blue
|
|
19
|
-
[LogLevel.Trace]: '\x1b[90m', // Gray
|
|
15
|
+
[LogLevel.Error]: supportsColoredStdout ? '\x1b[31m' : '', // Red
|
|
16
|
+
[LogLevel.Warn]: supportsColoredStdout ? '\x1b[33m' : '', // Yellow
|
|
17
|
+
[LogLevel.Info]: supportsColoredStdout ? '\x1b[32m' : '', // Green
|
|
18
|
+
[LogLevel.Verbose]: supportsColoredStdout ? '\x1b[36m' : '', // Cyan
|
|
19
|
+
[LogLevel.Debug]: supportsColoredStdout ? '\x1b[34m' : '', // Blue
|
|
20
|
+
[LogLevel.Trace]: supportsColoredStdout ? '\x1b[90m' : '', // Gray
|
|
20
21
|
};
|
|
21
|
-
const resetColor = '\x1b[0m';
|
|
22
|
-
const dimColor = '\x1b[2m';
|
|
22
|
+
const resetColor = supportsColoredStdout ? '\x1b[0m' : '';
|
|
23
|
+
const dimColor = supportsColoredStdout ? '\x1b[2m' : '';
|
|
23
24
|
/** Formats log entries in a human-readable, colorful format for development consoles. */
|
|
24
25
|
let PrettyPrintLogFormatter = class PrettyPrintLogFormatter extends LogFormatter {
|
|
25
26
|
format(payload) {
|
package/package.json
CHANGED
package/supports.d.ts
CHANGED
package/supports.js
CHANGED
|
@@ -3,3 +3,4 @@ export const supportsBlob = (typeof Blob == 'function');
|
|
|
3
3
|
export const supportsBuffer = (typeof Buffer == 'function');
|
|
4
4
|
export const supportsStructuredClone = (typeof structuredClone == 'function');
|
|
5
5
|
export const supportsNotification = (typeof Notification == 'function');
|
|
6
|
+
export const supportsColoredStdout = (typeof process == 'object' && process.stdout.hasColors());
|