@venizia/ignis-helpers 0.4.7-1 → 0.4.7-2
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/README.md +3 -3
- package/dist/esm/core.d.ts +1 -2
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +3 -2
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/base.d.ts +1 -1
- package/dist/esm/modules/base.d.ts.map +1 -1
- package/dist/esm/modules/base.js +14 -5
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts +15 -5
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.js +16 -4
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
- package/dist/esm/modules/logger/base/base.d.ts.map +1 -1
- package/dist/esm/modules/logger/base/base.js +3 -3
- package/dist/esm/modules/logger/base/base.js.map +1 -1
- package/dist/esm/modules/logger/base/console.d.ts +9 -4
- package/dist/esm/modules/logger/base/console.d.ts.map +1 -1
- package/dist/esm/modules/logger/base/console.js +15 -4
- package/dist/esm/modules/logger/base/console.js.map +1 -1
- package/dist/esm/modules/logger/common/constants.d.ts +0 -1
- package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/common/constants.js +0 -6
- package/dist/esm/modules/logger/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/common/debug-gate.d.ts +33 -0
- package/dist/esm/modules/logger/common/debug-gate.d.ts.map +1 -0
- package/dist/esm/modules/logger/common/debug-gate.js +51 -0
- package/dist/esm/modules/logger/common/debug-gate.js.map +1 -0
- package/dist/esm/modules/logger/common/index.d.ts +1 -0
- package/dist/esm/modules/logger/common/index.d.ts.map +1 -1
- package/dist/esm/modules/logger/common/index.js +1 -0
- package/dist/esm/modules/logger/common/index.js.map +1 -1
- package/dist/esm/modules/logger/common/types.d.ts +7 -0
- package/dist/esm/modules/logger/common/types.d.ts.map +1 -1
- package/dist/esm/modules/logger/common/types.js +16 -0
- package/dist/esm/modules/logger/common/types.js.map +1 -1
- package/dist/esm/modules/logger/factory.d.ts +29 -12
- package/dist/esm/modules/logger/factory.d.ts.map +1 -1
- package/dist/esm/modules/logger/factory.js +108 -50
- package/dist/esm/modules/logger/factory.js.map +1 -1
- package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/logger.js +3 -3
- package/dist/esm/modules/logger/hf/logger.js.map +1 -1
- package/dist/esm/modules/logger/index.d.ts +0 -1
- package/dist/esm/modules/logger/index.d.ts.map +1 -1
- package/dist/esm/modules/logger/index.js +0 -1
- package/dist/esm/modules/logger/index.js.map +1 -1
- package/dist/esm/utilities/module.utility.d.ts.map +1 -1
- package/dist/esm/utilities/module.utility.js +1 -0
- package/dist/esm/utilities/module.utility.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts.map +1 -1
- package/dist/esm/utilities/request.utility.js +1 -0
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +2 -2
- package/dist/esm/modules/logger/resolver.d.ts +0 -33
- package/dist/esm/modules/logger/resolver.d.ts.map +0 -1
- package/dist/esm/modules/logger/resolver.js +0 -95
- package/dist/esm/modules/logger/resolver.js.map +0 -1
- package/dist/esm/modules/logger/slot.d.ts +0 -44
- package/dist/esm/modules/logger/slot.d.ts.map +0 -1
- package/dist/esm/modules/logger/slot.js +0 -126
- package/dist/esm/modules/logger/slot.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC","sourcesContent":["export * from './constants';\nexport * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC","sourcesContent":["export * from './constants';\nexport * from './debug-gate';\nexport * from './types';\n"]}
|
|
@@ -6,7 +6,14 @@ export declare class LogLevels {
|
|
|
6
6
|
static readonly INFO = "info";
|
|
7
7
|
static readonly DEBUG = "debug";
|
|
8
8
|
static readonly SCHEME_SET: Set<string>;
|
|
9
|
+
/** From the most to the least severe: a threshold lets through its own level and every level before it. */
|
|
10
|
+
static readonly ORDER: ReadonlyArray<string>;
|
|
9
11
|
static isValid(input: string): boolean;
|
|
12
|
+
/** Whether a line of `level` passes a `threshold`: `debug` lets everything through, `error` only `error` and `emerg`. */
|
|
13
|
+
static isEnabled(opts: {
|
|
14
|
+
level: string;
|
|
15
|
+
threshold: string;
|
|
16
|
+
}): boolean;
|
|
10
17
|
}
|
|
11
18
|
export type TLogLevel = TConstValue<typeof LogLevels>;
|
|
12
19
|
/** The logging contract every consumer types against; which provider produced the logger is invisible behind it - only `factory.ts` and a provider's back-compat aliases may name a concrete logger class. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAEhE,qBAAa,SAAS;IACpB,MAAM,CAAC,QAAQ,CAAC,KA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jD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjD,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IACjE,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;CAClC;AAED,8FAA8F;AAC9F,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B"}
|
|
@@ -5,8 +5,24 @@ export class LogLevels {
|
|
|
5
5
|
static { this.INFO = 'info'; }
|
|
6
6
|
static { this.DEBUG = 'debug'; }
|
|
7
7
|
static { this.SCHEME_SET = new Set([this.ERROR, this.EMERG, this.WARN, this.INFO, this.DEBUG]); }
|
|
8
|
+
/** From the most to the least severe: a threshold lets through its own level and every level before it. */
|
|
9
|
+
static { this.ORDER = [
|
|
10
|
+
this.EMERG,
|
|
11
|
+
this.ERROR,
|
|
12
|
+
this.WARN,
|
|
13
|
+
this.INFO,
|
|
14
|
+
this.DEBUG,
|
|
15
|
+
]; }
|
|
8
16
|
static isValid(input) {
|
|
9
17
|
return this.SCHEME_SET.has(input);
|
|
10
18
|
}
|
|
19
|
+
/** Whether a line of `level` passes a `threshold`: `debug` lets everything through, `error` only `error` and `emerg`. */
|
|
20
|
+
static isEnabled(opts) {
|
|
21
|
+
const { level, threshold } = opts;
|
|
22
|
+
const levelRank = this.ORDER.indexOf(level);
|
|
23
|
+
const thresholdRank = this.ORDER.indexOf(threshold);
|
|
24
|
+
// An unknown level or threshold is never silenced: a typo must not hide a line.
|
|
25
|
+
return levelRank < 0 || thresholdRank < 0 || levelRank <= thresholdRank;
|
|
26
|
+
}
|
|
11
27
|
}
|
|
12
28
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/types.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,SAAS;aACJ,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEjG,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import { type AnyType, type TConstValue } from '@/common/types';\n\nexport class LogLevels {\n static readonly ERROR = 'error';\n static readonly EMERG = 'emerg';\n static readonly WARN = 'warn';\n static readonly INFO = 'info';\n static readonly DEBUG = 'debug';\n\n static readonly SCHEME_SET = new Set([this.ERROR, this.EMERG, this.WARN, this.INFO, this.DEBUG]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TLogLevel = TConstValue<typeof LogLevels>;\n\n/** The logging contract every consumer types against; which provider produced the logger is invisible behind it - only `factory.ts` and a provider's back-compat aliases may name a concrete logger class. */\nexport interface ILogger {\n debug(message: string, ...args: AnyType[]): void;\n info(message: string, ...args: AnyType[]): void;\n warn(message: string, ...args: AnyType[]): void;\n error(message: string, ...args: AnyType[]): void;\n emerg(message: string, ...args: AnyType[]): void;\n log(level: TLogLevel, message: string, ...args: AnyType[]): void;\n for(methodName: string): ILogger;\n}\n\n/** Static-side contract a provider class satisfies - WinstonLogger and PinoLogger both do. */\nexport interface ILoggerProvider {\n get(scope: string): ILogger;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/types.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,SAAS;aACJ,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEjG,2GAA2G;aAC3F,UAAK,GAA0B;QAC7C,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,KAAK;KACX,CAAC;IAEF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,yHAAyH;IACzH,MAAM,CAAC,SAAS,CAAC,IAA0C;QACzD,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAEpD,gFAAgF;QAChF,OAAO,SAAS,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC,IAAI,SAAS,IAAI,aAAa,CAAC;IAC1E,CAAC","sourcesContent":["import { type AnyType, type TConstValue } from '@/common/types';\n\nexport class LogLevels {\n static readonly ERROR = 'error';\n static readonly EMERG = 'emerg';\n static readonly WARN = 'warn';\n static readonly INFO = 'info';\n static readonly DEBUG = 'debug';\n\n static readonly SCHEME_SET = new Set([this.ERROR, this.EMERG, this.WARN, this.INFO, this.DEBUG]);\n\n /** From the most to the least severe: a threshold lets through its own level and every level before it. */\n static readonly ORDER: ReadonlyArray<string> = [\n this.EMERG,\n this.ERROR,\n this.WARN,\n this.INFO,\n this.DEBUG,\n ];\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n\n /** Whether a line of `level` passes a `threshold`: `debug` lets everything through, `error` only `error` and `emerg`. */\n static isEnabled(opts: { level: string; threshold: string }): boolean {\n const { level, threshold } = opts;\n const levelRank = this.ORDER.indexOf(level);\n const thresholdRank = this.ORDER.indexOf(threshold);\n\n // An unknown level or threshold is never silenced: a typo must not hide a line.\n return levelRank < 0 || thresholdRank < 0 || levelRank <= thresholdRank;\n }\n}\n\nexport type TLogLevel = TConstValue<typeof LogLevels>;\n\n/** The logging contract every consumer types against; which provider produced the logger is invisible behind it - only `factory.ts` and a provider's back-compat aliases may name a concrete logger class. */\nexport interface ILogger {\n debug(message: string, ...args: AnyType[]): void;\n info(message: string, ...args: AnyType[]): void;\n warn(message: string, ...args: AnyType[]): void;\n error(message: string, ...args: AnyType[]): void;\n emerg(message: string, ...args: AnyType[]): void;\n log(level: TLogLevel, message: string, ...args: AnyType[]): void;\n for(methodName: string): ILogger;\n}\n\n/** Static-side contract a provider class satisfies - WinstonLogger and PinoLogger both do. */\nexport interface ILoggerProvider {\n get(scope: string): ILogger;\n}\n"]}
|
|
@@ -1,22 +1,39 @@
|
|
|
1
|
-
import { type ILogger, type ILoggerProvider } from './common/types.js';
|
|
2
|
-
/**
|
|
1
|
+
import { type ILogger, type ILoggerProvider, type TLogLevel } from './common/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The one way to get a logger, and the same everywhere: the server, a script and a browser. It names no provider: the
|
|
4
|
+
* default is the console (`ConsoleLogger`), and an application chooses another with `use()`. It imports nothing from
|
|
5
|
+
* node, so it is part of the browser-pure `core` entry.
|
|
6
|
+
*/
|
|
3
7
|
export declare class LoggerFactory {
|
|
4
|
-
private static provider?;
|
|
5
8
|
private static cache;
|
|
6
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Choose the application's provider and/or the level. A provider re-points every wrapper issued so far. The level
|
|
11
|
+
* (a `LogLevels` value the application passes) is applied by the wrapper to every provider alike, and it also
|
|
12
|
+
* decides whether `debug` lines are written at all: `debug` turns the gate on, anything above it turns it off,
|
|
13
|
+
* whatever the environment says. A level that is not a `LogLevels` value (a typo, an uppercase name from the
|
|
14
|
+
* environment) is ignored: it must never open debug.
|
|
15
|
+
*/
|
|
7
16
|
static use(opts: {
|
|
17
|
+
provider?: ILoggerProvider;
|
|
18
|
+
level?: TLogLevel;
|
|
19
|
+
}): void;
|
|
20
|
+
/** Choose `provider` only when the application has not chosen one: a framework's startup default, never an override. */
|
|
21
|
+
static useUnlessChosen(opts: {
|
|
8
22
|
provider: ILoggerProvider;
|
|
9
23
|
}): void;
|
|
24
|
+
/** Whether an application (or a framework default through `useUnlessChosen`) has chosen a provider. */
|
|
25
|
+
static isChosen(): boolean;
|
|
26
|
+
/** The slot is the only record of the choice, so a `use()` or a `reset()` in any copy of the module is seen by all. */
|
|
10
27
|
static currentProvider(): ILoggerProvider;
|
|
11
|
-
/**
|
|
28
|
+
/** Moves whenever a provider is chosen or reset, in any copy: a wrapper that cached its logger takes it again. */
|
|
29
|
+
static currentGeneration(): number;
|
|
30
|
+
private static bumpGeneration;
|
|
31
|
+
/** The level the application set, or `undefined`: then every provider applies its own gate. */
|
|
32
|
+
static currentLevel(): TLogLevel | undefined;
|
|
33
|
+
/** The provider chosen by any copy of this module, if any. */
|
|
12
34
|
private static sharedProvider;
|
|
13
|
-
|
|
35
|
+
/** Back to the default provider and no level, and every wrapper takes the console again: for a test, or a host that starts over. */
|
|
36
|
+
static reset(): void;
|
|
14
37
|
static getLogger(scopes: string[]): ILogger;
|
|
15
38
|
}
|
|
16
|
-
/** Provider-following facade: always resolves through the registered provider. */
|
|
17
|
-
export declare class ApplicationLogger {
|
|
18
|
-
static get(opts: {
|
|
19
|
-
scope: string;
|
|
20
|
-
}): ILogger;
|
|
21
|
-
}
|
|
22
39
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAa,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAkG/F;;;;GAIG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAsC;IAE1D;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,EAAE,eAAe,CAAC;QAAC,KAAK,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,IAAI;IAqBzE,wHAAwH;IACxH,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,eAAe,CAAA;KAAE,GAAG,IAAI;IAMjE,uGAAuG;IACvG,MAAM,CAAC,QAAQ,IAAI,OAAO;IAI1B,uHAAuH;IACvH,MAAM,CAAC,eAAe,IAAI,eAAe;IAIzC,kHAAkH;IAClH,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAKlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B,+FAA+F;IAC/F,MAAM,CAAC,YAAY,IAAI,SAAS,GAAG,SAAS;IAK5C,8DAA8D;IAC9D,OAAO,CAAC,MAAM,CAAC,cAAc;IAK7B,oIAAoI;IACpI,MAAM,CAAC,KAAK,IAAI,IAAI;IAUpB,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO;CAW5C"}
|
|
@@ -1,37 +1,70 @@
|
|
|
1
|
-
import { getError } from '@venizia/ignis-inversion';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
1
|
import { AbstractLogger } from './base/abstract.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
2
|
+
import { ConsoleLogger } from './base/console.js';
|
|
3
|
+
import { LoggerDebugGate } from './common/debug-gate.js';
|
|
4
|
+
import { LogLevels } from './common/types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Stable wrapper the factory hands out. The delegate is resolved on the first log call or by `use()`, never at
|
|
7
|
+
* construction, so no provider is touched until a line is written. The wrapper also applies the factory's level to every
|
|
8
|
+
* provider the same way. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables.
|
|
9
|
+
*/
|
|
6
10
|
class LoggerDelegator extends AbstractLogger {
|
|
7
11
|
constructor(scope) {
|
|
8
12
|
super();
|
|
9
13
|
this.scope = scope;
|
|
14
|
+
this._generation = -1;
|
|
10
15
|
}
|
|
16
|
+
/** Takes the new provider's logger for this scope at once: the wrappers of this copy do not wait for their next line. */
|
|
11
17
|
repoint(provider) {
|
|
12
18
|
this._delegate = provider.get(this.scope);
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
20
|
+
this._generation = LoggerFactory.currentGeneration();
|
|
13
21
|
}
|
|
22
|
+
/** The provider's logger for this scope, taken again whenever any copy of the module chose another provider (one integer compare per line). */
|
|
14
23
|
delegate() {
|
|
15
24
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
16
|
-
|
|
25
|
+
const generation = LoggerFactory.currentGeneration();
|
|
26
|
+
if (!this._delegate || this._generation !== generation) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
28
|
+
this._delegate = LoggerFactory.currentProvider().get(this.scope);
|
|
29
|
+
this._generation = generation;
|
|
30
|
+
}
|
|
31
|
+
return this._delegate;
|
|
32
|
+
}
|
|
33
|
+
/** The level the application set, else the shared debug gate for `debug`: a provider that has no gate of its own is gated the same way. */
|
|
34
|
+
isEnabled(level) {
|
|
35
|
+
if (level === LogLevels.DEBUG && !LoggerDebugGate.isOpen()) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
39
|
+
const threshold = LoggerFactory.currentLevel();
|
|
40
|
+
return threshold === undefined || LogLevels.isEnabled({ level, threshold });
|
|
41
|
+
}
|
|
42
|
+
/** The one place a level method passes its line to the provider, after the one level check. */
|
|
43
|
+
forward(opts) {
|
|
44
|
+
const { method, message, args } = opts;
|
|
45
|
+
if (this.isEnabled(method)) {
|
|
46
|
+
this.delegate()[method](message, ...args);
|
|
47
|
+
}
|
|
17
48
|
}
|
|
18
49
|
debug(message, ...args) {
|
|
19
|
-
this.
|
|
50
|
+
this.forward({ method: LogLevels.DEBUG, message, args });
|
|
20
51
|
}
|
|
21
52
|
info(message, ...args) {
|
|
22
|
-
this.
|
|
53
|
+
this.forward({ method: LogLevels.INFO, message, args });
|
|
23
54
|
}
|
|
24
55
|
warn(message, ...args) {
|
|
25
|
-
this.
|
|
56
|
+
this.forward({ method: LogLevels.WARN, message, args });
|
|
26
57
|
}
|
|
27
58
|
error(message, ...args) {
|
|
28
|
-
this.
|
|
59
|
+
this.forward({ method: LogLevels.ERROR, message, args });
|
|
29
60
|
}
|
|
30
61
|
emerg(message, ...args) {
|
|
31
|
-
this.
|
|
62
|
+
this.forward({ method: LogLevels.EMERG, message, args });
|
|
32
63
|
}
|
|
33
64
|
log(level, message, ...args) {
|
|
34
|
-
this.
|
|
65
|
+
if (this.isEnabled(level)) {
|
|
66
|
+
this.delegate().log(level, message, ...args);
|
|
67
|
+
}
|
|
35
68
|
}
|
|
36
69
|
for(methodName) {
|
|
37
70
|
const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;
|
|
@@ -39,52 +72,85 @@ class LoggerDelegator extends AbstractLogger {
|
|
|
39
72
|
return LoggerFactory.getLogger([childScope]);
|
|
40
73
|
}
|
|
41
74
|
}
|
|
42
|
-
/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The provider
|
|
75
|
+
/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The chosen provider, the level and a counter of choices live in these globalThis slots so `use()` in one copy is seen, on the next line, by the loggers of the other. */
|
|
43
76
|
const PROVIDER_SLOT = Symbol.for('ignis:logger-provider');
|
|
44
|
-
|
|
77
|
+
const LEVEL_SLOT = Symbol.for('ignis:logger-level');
|
|
78
|
+
const GENERATION_SLOT = Symbol.for('ignis:logger-generation');
|
|
79
|
+
/**
|
|
80
|
+
* The one way to get a logger, and the same everywhere: the server, a script and a browser. It names no provider: the
|
|
81
|
+
* default is the console (`ConsoleLogger`), and an application chooses another with `use()`. It imports nothing from
|
|
82
|
+
* node, so it is part of the browser-pure `core` entry.
|
|
83
|
+
*/
|
|
45
84
|
export class LoggerFactory {
|
|
46
85
|
static { this.cache = new Map(); }
|
|
47
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Choose the application's provider and/or the level. A provider re-points every wrapper issued so far. The level
|
|
88
|
+
* (a `LogLevels` value the application passes) is applied by the wrapper to every provider alike, and it also
|
|
89
|
+
* decides whether `debug` lines are written at all: `debug` turns the gate on, anything above it turns it off,
|
|
90
|
+
* whatever the environment says. A level that is not a `LogLevels` value (a typo, an uppercase name from the
|
|
91
|
+
* environment) is ignored: it must never open debug.
|
|
92
|
+
*/
|
|
48
93
|
static use(opts) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
94
|
+
const { provider, level } = opts;
|
|
95
|
+
if (level !== undefined && LogLevels.isValid(level)) {
|
|
96
|
+
Reflect.set(globalThis, LEVEL_SLOT, level);
|
|
97
|
+
LoggerDebugGate.force({
|
|
98
|
+
isOpen: LogLevels.isEnabled({ level: LogLevels.DEBUG, threshold: level }),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (provider === undefined) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
Reflect.set(globalThis, PROVIDER_SLOT, provider);
|
|
105
|
+
this.bumpGeneration();
|
|
106
|
+
for (const wrapper of this.cache.values()) {
|
|
107
|
+
wrapper.repoint(provider);
|
|
54
108
|
}
|
|
55
109
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
110
|
+
/** Choose `provider` only when the application has not chosen one: a framework's startup default, never an override. */
|
|
111
|
+
static useUnlessChosen(opts) {
|
|
112
|
+
if (!this.isChosen()) {
|
|
113
|
+
this.use({ provider: opts.provider });
|
|
60
114
|
}
|
|
61
|
-
return this.provider;
|
|
62
115
|
}
|
|
63
|
-
/**
|
|
116
|
+
/** Whether an application (or a framework default through `useUnlessChosen`) has chosen a provider. */
|
|
117
|
+
static isChosen() {
|
|
118
|
+
return this.sharedProvider() !== undefined;
|
|
119
|
+
}
|
|
120
|
+
/** The slot is the only record of the choice, so a `use()` or a `reset()` in any copy of the module is seen by all. */
|
|
121
|
+
static currentProvider() {
|
|
122
|
+
return this.sharedProvider() ?? ConsoleLogger;
|
|
123
|
+
}
|
|
124
|
+
/** Moves whenever a provider is chosen or reset, in any copy: a wrapper that cached its logger takes it again. */
|
|
125
|
+
static currentGeneration() {
|
|
126
|
+
const generation = Reflect.get(globalThis, GENERATION_SLOT);
|
|
127
|
+
return generation ?? 0;
|
|
128
|
+
}
|
|
129
|
+
static bumpGeneration() {
|
|
130
|
+
Reflect.set(globalThis, GENERATION_SLOT, this.currentGeneration() + 1);
|
|
131
|
+
}
|
|
132
|
+
/** The level the application set, or `undefined`: then every provider applies its own gate. */
|
|
133
|
+
static currentLevel() {
|
|
134
|
+
const level = Reflect.get(globalThis, LEVEL_SLOT);
|
|
135
|
+
return level;
|
|
136
|
+
}
|
|
137
|
+
/** The provider chosen by any copy of this module, if any. */
|
|
64
138
|
static sharedProvider() {
|
|
65
139
|
const shared = Reflect.get(globalThis, PROVIDER_SLOT);
|
|
66
140
|
return shared;
|
|
67
141
|
}
|
|
68
|
-
|
|
69
|
-
static
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
'[LoggerFactory] No logger provider is registered and the default (winston) could not be loaded.',
|
|
77
|
-
'Either install it: `bun add winston winston-transport winston-daily-rotate-file`,',
|
|
78
|
-
'or register a provider at your entrypoint: `LoggerFactory.use({ provider })` with a class',
|
|
79
|
-
"from '@venizia/ignis-helpers/winston' or '@venizia/ignis-helpers/pino'.",
|
|
80
|
-
'Compiled binaries (bun build --compile) MUST register explicitly.',
|
|
81
|
-
`Cause: ${error instanceof Error ? error.message : String(error)}`,
|
|
82
|
-
].join(' '),
|
|
83
|
-
});
|
|
142
|
+
/** Back to the default provider and no level, and every wrapper takes the console again: for a test, or a host that starts over. */
|
|
143
|
+
static reset() {
|
|
144
|
+
Reflect.deleteProperty(globalThis, PROVIDER_SLOT);
|
|
145
|
+
Reflect.deleteProperty(globalThis, LEVEL_SLOT);
|
|
146
|
+
LoggerDebugGate.force({ isOpen: undefined });
|
|
147
|
+
this.bumpGeneration();
|
|
148
|
+
for (const wrapper of this.cache.values()) {
|
|
149
|
+
wrapper.repoint(ConsoleLogger);
|
|
84
150
|
}
|
|
85
151
|
}
|
|
86
152
|
static getLogger(scopes) {
|
|
87
|
-
const scope = scopes.join('-');
|
|
153
|
+
const scope = scopes.filter((part) => part.length > 0).join('-');
|
|
88
154
|
let cached = this.cache.get(scope);
|
|
89
155
|
if (!cached) {
|
|
90
156
|
cached = new LoggerDelegator(scope);
|
|
@@ -93,12 +159,4 @@ export class LoggerFactory {
|
|
|
93
159
|
return cached;
|
|
94
160
|
}
|
|
95
161
|
}
|
|
96
|
-
/** Provider-following facade: always resolves through the registered provider. */
|
|
97
|
-
export class ApplicationLogger {
|
|
98
|
-
static get(opts) {
|
|
99
|
-
return LoggerFactory.getLogger([typeof opts === 'string' ? opts : opts.scope]);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
// Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.
|
|
103
|
-
LoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });
|
|
104
162
|
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,8PAA8P;AAC9P,MAAM,eAAgB,SAAQ,cAAc;IAG1C,YAA6B,KAAa;QACxC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAQ;IAE1C,CAAC;IAED,OAAO,CAAC,QAAyB;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEO,QAAQ;QACd,mEAAmE;QACnE,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,QAAQ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CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;iBACnE,CAAC,IAAI,CAAC,GAAG,CAAC;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AAGH,kFAAkF;AAClF,MAAM,OAAO,iBAAiB;IAG5B,MAAM,CAAC,GAAG,CAAC,IAAgC;QACzC,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACjF,CAAC;CACF;AAED,2OAA2O;AAC3O,cAAc,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { getError } from '@venizia/ignis-inversion';\nimport { createRequire } from 'node:module';\nimport { AbstractLogger } from './base/abstract';\nimport { type ILogger, type ILoggerProvider, type TLogLevel } from './common/types';\nimport { LoggerResolver } from './resolver';\n\n/** Stable wrapper the factory hands out; the delegate resolves lazily (first log call or `use()`), never at construction, so no provider loads until needed. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables. */\nclass LoggerDelegator extends AbstractLogger {\n private _delegate?: ILogger;\n\n constructor(private readonly scope: string) {\n super();\n }\n\n repoint(provider: ILoggerProvider): void {\n this._delegate = provider.get(this.scope);\n }\n\n private delegate(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return (this._delegate ??= LoggerFactory.currentProvider().get(this.scope));\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.delegate().debug(message, ...args);\n }\n\n info(message: string, ...args: AnyType[]) {\n this.delegate().info(message, ...args);\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.delegate().warn(message, ...args);\n }\n\n error(message: string, ...args: AnyType[]) {\n this.delegate().error(message, ...args);\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.delegate().emerg(message, ...args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n this.delegate().log(level, message, ...args);\n }\n\n for(methodName: string): ILogger {\n const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return LoggerFactory.getLogger([childScope]);\n }\n}\n\n/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The provider lives in this globalThis slot so `use()` in one copy is seen by the other. */\nconst PROVIDER_SLOT = Symbol.for('ignis:logger-provider');\n\n/** Provider-agnostic acquisition path. Exactly ONE provider is ever loaded - the one registered via `use()`, or the winston default at first unregistered log call. */\nexport class LoggerFactory {\n private static provider?: ILoggerProvider;\n private static cache = new Map<string, LoggerDelegator>();\n\n /** Register the application's provider. Re-points every wrapper issued so far. */\n static use(opts: { provider: ILoggerProvider }): void {\n this.provider = opts.provider;\n Reflect.set(globalThis, PROVIDER_SLOT, opts.provider);\n const cacheValues = this.cache.values();\n for (const wrapper of cacheValues) {\n wrapper.repoint(opts.provider);\n }\n }\n\n static currentProvider(): ILoggerProvider {\n if (!this.provider) {\n this.provider = this.sharedProvider() ?? this.loadDefaultProvider();\n Reflect.set(globalThis, PROVIDER_SLOT, this.provider);\n }\n\n return this.provider;\n }\n\n /** The provider another copy of this module registered, if any. */\n private static sharedProvider(): ILoggerProvider | undefined {\n const shared: ILoggerProvider | undefined = Reflect.get(globalThis, PROVIDER_SLOT);\n return shared;\n }\n\n // winston is an optional peer; compiled binaries must register a provider explicitly because only a class reference carries a provider into a bundle.\n private static loadDefaultProvider(): ILoggerProvider {\n try {\n return createRequire(__filename)('./winston').WinstonLogger;\n } catch (error) {\n throw getError({\n message: [\n '[LoggerFactory] No logger provider is registered and the default (winston) could not be loaded.',\n 'Either install it: `bun add winston winston-transport winston-daily-rotate-file`,',\n 'or register a provider at your entrypoint: `LoggerFactory.use({ provider })` with a class',\n \"from '@venizia/ignis-helpers/winston' or '@venizia/ignis-helpers/pino'.\",\n 'Compiled binaries (bun build --compile) MUST register explicitly.',\n `Cause: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n }\n\n static getLogger(scopes: string[]): ILogger {\n const scope = scopes.join('-');\n let cached = this.cache.get(scope);\n\n if (!cached) {\n cached = new LoggerDelegator(scope);\n this.cache.set(scope, cached);\n }\n\n return cached;\n }\n}\n\n/** Provider-following facade: always resolves through the registered provider. */\nexport class ApplicationLogger {\n static get(opts: { scope: string }): ILogger;\n\n static get(opts: { scope: string } | string): ILogger {\n return LoggerFactory.getLogger([typeof opts === 'string' ? opts : opts.scope]);\n }\n}\n\n// Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.\nLoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });\n"]}
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAsC,SAAS,EAAkB,MAAM,gBAAgB,CAAC;AAE/F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AAE,aAAa,CAAC,CAAC;QAClD,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAC/C,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YAC1C,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjE,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { AbstractLogger } from './base/abstract';\nimport { ConsoleLogger } from './base/console';\nimport { LoggerDebugGate } from './common/debug-gate';\nimport { type ILogger, type ILoggerProvider, LogLevels, type TLogLevel } from './common/types';\n\n/**\n * Stable wrapper the factory hands out. The delegate is resolved on the first log call or by `use()`, never at\n * construction, so no provider is touched until a line is written. The wrapper also applies the factory's level to every\n * provider the same way. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables.\n */\nclass LoggerDelegator extends AbstractLogger {\n private _delegate?: ILogger;\n private _generation = -1;\n\n constructor(private readonly scope: string) {\n super();\n }\n\n /** Takes the new provider's logger for this scope at once: the wrappers of this copy do not wait for their next line. */\n repoint(provider: ILoggerProvider): void {\n this._delegate = provider.get(this.scope);\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n this._generation = LoggerFactory.currentGeneration();\n }\n\n /** The provider's logger for this scope, taken again whenever any copy of the module chose another provider (one integer compare per line). */\n private delegate(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n const generation = LoggerFactory.currentGeneration();\n\n if (!this._delegate || this._generation !== generation) {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n this._delegate = LoggerFactory.currentProvider().get(this.scope);\n this._generation = generation;\n }\n\n return this._delegate;\n }\n\n /** The level the application set, else the shared debug gate for `debug`: a provider that has no gate of its own is gated the same way. */\n private isEnabled(level: TLogLevel): boolean {\n if (level === LogLevels.DEBUG && !LoggerDebugGate.isOpen()) {\n return false;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n const threshold = LoggerFactory.currentLevel();\n return threshold === undefined || LogLevels.isEnabled({ level, threshold });\n }\n\n /** The one place a level method passes its line to the provider, after the one level check. */\n private forward(opts: {\n method: 'debug' | 'info' | 'warn' | 'error' | 'emerg';\n message: string;\n args: AnyType[];\n }): void {\n const { method, message, args } = opts;\n\n if (this.isEnabled(method)) {\n this.delegate()[method](message, ...args);\n }\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.forward({ method: LogLevels.DEBUG, message, args });\n }\n\n info(message: string, ...args: AnyType[]) {\n this.forward({ method: LogLevels.INFO, message, args });\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.forward({ method: LogLevels.WARN, message, args });\n }\n\n error(message: string, ...args: AnyType[]) {\n this.forward({ method: LogLevels.ERROR, message, args });\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.forward({ method: LogLevels.EMERG, message, args });\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n if (this.isEnabled(level)) {\n this.delegate().log(level, message, ...args);\n }\n }\n\n for(methodName: string): ILogger {\n const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return LoggerFactory.getLogger([childScope]);\n }\n}\n\n/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The chosen provider, the level and a counter of choices live in these globalThis slots so `use()` in one copy is seen, on the next line, by the loggers of the other. */\nconst PROVIDER_SLOT = Symbol.for('ignis:logger-provider');\nconst LEVEL_SLOT = Symbol.for('ignis:logger-level');\nconst GENERATION_SLOT = Symbol.for('ignis:logger-generation');\n\n/**\n * The one way to get a logger, and the same everywhere: the server, a script and a browser. It names no provider: the\n * default is the console (`ConsoleLogger`), and an application chooses another with `use()`. It imports nothing from\n * node, so it is part of the browser-pure `core` entry.\n */\nexport class LoggerFactory {\n private static cache = new Map<string, LoggerDelegator>();\n\n /**\n * Choose the application's provider and/or the level. A provider re-points every wrapper issued so far. The level\n * (a `LogLevels` value the application passes) is applied by the wrapper to every provider alike, and it also\n * decides whether `debug` lines are written at all: `debug` turns the gate on, anything above it turns it off,\n * whatever the environment says. A level that is not a `LogLevels` value (a typo, an uppercase name from the\n * environment) is ignored: it must never open debug.\n */\n static use(opts: { provider?: ILoggerProvider; level?: TLogLevel }): void {\n const { provider, level } = opts;\n\n if (level !== undefined && LogLevels.isValid(level)) {\n Reflect.set(globalThis, LEVEL_SLOT, level);\n LoggerDebugGate.force({\n isOpen: LogLevels.isEnabled({ level: LogLevels.DEBUG, threshold: level }),\n });\n }\n\n if (provider === undefined) {\n return;\n }\n\n Reflect.set(globalThis, PROVIDER_SLOT, provider);\n this.bumpGeneration();\n for (const wrapper of this.cache.values()) {\n wrapper.repoint(provider);\n }\n }\n\n /** Choose `provider` only when the application has not chosen one: a framework's startup default, never an override. */\n static useUnlessChosen(opts: { provider: ILoggerProvider }): void {\n if (!this.isChosen()) {\n this.use({ provider: opts.provider });\n }\n }\n\n /** Whether an application (or a framework default through `useUnlessChosen`) has chosen a provider. */\n static isChosen(): boolean {\n return this.sharedProvider() !== undefined;\n }\n\n /** The slot is the only record of the choice, so a `use()` or a `reset()` in any copy of the module is seen by all. */\n static currentProvider(): ILoggerProvider {\n return this.sharedProvider() ?? ConsoleLogger;\n }\n\n /** Moves whenever a provider is chosen or reset, in any copy: a wrapper that cached its logger takes it again. */\n static currentGeneration(): number {\n const generation: number | undefined = Reflect.get(globalThis, GENERATION_SLOT);\n return generation ?? 0;\n }\n\n private static bumpGeneration(): void {\n Reflect.set(globalThis, GENERATION_SLOT, this.currentGeneration() + 1);\n }\n\n /** The level the application set, or `undefined`: then every provider applies its own gate. */\n static currentLevel(): TLogLevel | undefined {\n const level: TLogLevel | undefined = Reflect.get(globalThis, LEVEL_SLOT);\n return level;\n }\n\n /** The provider chosen by any copy of this module, if any. */\n private static sharedProvider(): ILoggerProvider | undefined {\n const shared: ILoggerProvider | undefined = Reflect.get(globalThis, PROVIDER_SLOT);\n return shared;\n }\n\n /** Back to the default provider and no level, and every wrapper takes the console again: for a test, or a host that starts over. */\n static reset(): void {\n Reflect.deleteProperty(globalThis, PROVIDER_SLOT);\n Reflect.deleteProperty(globalThis, LEVEL_SLOT);\n LoggerDebugGate.force({ isOpen: undefined });\n this.bumpGeneration();\n for (const wrapper of this.cache.values()) {\n wrapper.repoint(ConsoleLogger);\n }\n }\n\n static getLogger(scopes: string[]): ILogger {\n const scope = scopes.filter((part) => part.length > 0).join('-');\n let cached = this.cache.get(scope);\n\n if (!cached) {\n cached = new LoggerDelegator(scope);\n this.cache.set(scope, cached);\n }\n\n return cached;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/hf/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sour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EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIhD,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAChE,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,IAAI;IAerD,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;CAGjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractLogger } from '../base/index.js';
|
|
2
|
-
import { LogLevels,
|
|
2
|
+
import { LogLevels, LoggerDebugGate } from '../common/index.js';
|
|
3
3
|
import { LogFormatUtility } from '../formatting/index.js';
|
|
4
4
|
import { BUFFER_SIZE, ENTRY_SIZE, HF_LEVEL_CODES, HF_MESSAGE_MAX_BYTES, HF_SCOPE_MAX_BYTES, MESSAGE_CACHE_CAP, OFFSET_LEVEL, OFFSET_MESSAGE, OFFSET_MESSAGE_LENGTH, OFFSET_SCOPE, OFFSET_SCOPE_LENGTH, } from './common/index.js';
|
|
5
5
|
import { HfLogRing } from './ring.js';
|
|
@@ -76,7 +76,7 @@ export class HfLogger extends AbstractLogger {
|
|
|
76
76
|
this.writeEntry(levelCode, HfLogger.encodeMessage(message));
|
|
77
77
|
}
|
|
78
78
|
debug(message, ...args) {
|
|
79
|
-
if (!
|
|
79
|
+
if (!LoggerDebugGate.isOpen()) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
this.writeString(HF_LEVEL_CODES.debug, message, args);
|
|
@@ -94,7 +94,7 @@ export class HfLogger extends AbstractLogger {
|
|
|
94
94
|
this.writeString(HF_LEVEL_CODES.emerg, message, args);
|
|
95
95
|
}
|
|
96
96
|
log(level, message, ...args) {
|
|
97
|
-
if (level === LogLevels.DEBUG && !
|
|
97
|
+
if (level === LogLevels.DEBUG && !LoggerDebugGate.isOpen()) {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
const levelCode = Object.hasOwn(HF_LEVEL_CODES, level)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../src/modules/logger/hf/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAgB,SAAS,EAAE,gBAAgB,EAAkB,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,WAAW,EACX,UAAU,EACV,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GAEpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,4KAA4K;AAC5K,MAAM,OAAO,QAAS,SAAQ,cAAc;aAClB,gBAAW,GAAG,IAAI,WAAW,EAAE,CAAC;aAChC,eAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;aACpD,UAAK,GAAG,IAAI,GAAG,EAAoB,CAAC;aACpC,iBAAY,GAAG,IAAI,GAAG,EAAsB,CAAC;IAQ5D,YAAoB,KAAa;QAC/B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;IAC9B,CAAC;IAEO,MAAM,CAAC,WAAW,CAAC,KAAa;QACtC,IAAI,KAAK,GAAG,QAAQ,CAAC,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,OAAO;QACT,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,KAAK,CAAC;YACpD,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC;YACvB,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC;QACxB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3C,OAAO;QACT,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,UAAkB;QACpB,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC;IACrD,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { AbstractLogger } from '../base';\nimport { type ILogger, LogLevels, SHOULD_LOG_DEBUG, type TLogLevel } from '../common';\nimport { LogFormatUtility } from '../formatting';\nimport {\n BUFFER_SIZE,\n ENTRY_SIZE,\n HF_LEVEL_CODES,\n HF_MESSAGE_MAX_BYTES,\n HF_SCOPE_MAX_BYTES,\n MESSAGE_CACHE_CAP,\n OFFSET_LEVEL,\n OFFSET_MESSAGE,\n OFFSET_MESSAGE_LENGTH,\n OFFSET_SCOPE,\n OFFSET_SCOPE_LENGTH,\n type TRingState,\n} from './common';\nimport { HfLogRing } from './ring';\n\n/** Ring-buffer logger for hot paths; extends AbstractLogger, NOT BaseLogger - BaseLogger's string-sink plumbing is exactly the cost this implementation exists to avoid. */\nexport class HfLogger extends AbstractLogger {\n private static readonly textEncoder = new TextEncoder();\n private static readonly scopeCache = new Map<string, Uint8Array>();\n private static cache = new Map<string, HfLogger>();\n private static messageCache = new Map<string, Uint8Array>();\n\n private readonly scope: string;\n private readonly scopeBytes: Uint8Array;\n private readonly scopeLength: number;\n // Resolved once at construction (get() has already allocated the ring): saves a call and a null-check per log on a path budgeted in nanoseconds.\n private readonly ring: TRingState;\n\n private constructor(scope: string) {\n super();\n this.scope = scope;\n this.scopeBytes = HfLogger.encodeScope(scope);\n this.scopeLength = this.scopeBytes.length;\n this.ring = HfLogRing.get();\n }\n\n private static encodeScope(scope: string): Uint8Array {\n let bytes = HfLogger.scopeCache.get(scope);\n if (!bytes) {\n bytes = HfLogger.textEncoder.encode(scope).subarray(0, HF_SCOPE_MAX_BYTES);\n HfLogger.scopeCache.set(scope, bytes);\n }\n return bytes;\n }\n\n static get(scope: string): HfLogger {\n let logger = this.cache.get(scope);\n if (!logger) {\n logger = new HfLogger(scope); // first logger allocates the ring - never at import\n this.cache.set(scope, logger);\n }\n return logger;\n }\n\n /** Pre-encode a message at initialization time; the cache is FIFO-bounded so dynamic strings can't grow it without limit. */\n static encodeMessage(message: string): Uint8Array {\n const cached = this.messageCache.get(message);\n if (cached) {\n return cached;\n }\n\n const bytes = HfLogger.textEncoder.encode(message);\n if (this.messageCache.size >= MESSAGE_CACHE_CAP) {\n this.evictOldestMessage();\n }\n this.messageCache.set(message, bytes);\n return bytes;\n }\n\n private static evictOldestMessage(): void {\n const oldest = this.messageCache.keys().next().value;\n if (oldest === undefined) {\n return;\n }\n this.messageCache.delete(oldest);\n }\n\n private writeEntry(levelCode: number, messageBytes: Uint8Array): void {\n const ring = this.ring;\n const slot = ring.writeIndex++ & (BUFFER_SIZE - 1);\n const offset = slot * ENTRY_SIZE;\n ring.f64[offset >> 3] = performance.timeOrigin + performance.now();\n const bytes = ring.bytes;\n bytes[offset + OFFSET_LEVEL] = levelCode;\n bytes[offset + OFFSET_SCOPE_LENGTH] = this.scopeLength;\n bytes.set(this.scopeBytes, offset + OFFSET_SCOPE);\n const messageLength =\n messageBytes.length < HF_MESSAGE_MAX_BYTES ? messageBytes.length : HF_MESSAGE_MAX_BYTES;\n bytes[offset + OFFSET_MESSAGE_LENGTH] = messageLength;\n bytes.set(\n messageLength === messageBytes.length\n ? messageBytes\n : messageBytes.subarray(0, messageLength),\n offset + OFFSET_MESSAGE,\n );\n }\n\n private writeString(levelCode: number, message: string, args: Array<AnyType>): void {\n if (args.length > 0) {\n // Slow path, documented: args are formatted (deep inspection + redaction) - never dropped.\n this.writeEntry(\n levelCode,\n HfLogger.textEncoder.encode(LogFormatUtility.formatMessage({ message, args })),\n );\n return;\n }\n this.writeEntry(levelCode, HfLogger.encodeMessage(message));\n }\n\n debug(message: string, ...args: AnyType[]): void {\n if (!SHOULD_LOG_DEBUG) {\n return;\n }\n this.writeString(HF_LEVEL_CODES.debug, message, args);\n }\n\n info(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.info, message, args);\n }\n\n warn(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.warn, message, args);\n }\n\n error(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.error, message, args);\n }\n\n emerg(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.emerg, message, args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]): void;\n log(level: TLogLevel, messageBytes: Uint8Array): void;\n log(level: TLogLevel, message: string | Uint8Array, ...args: AnyType[]): void {\n if (level === LogLevels.DEBUG && !SHOULD_LOG_DEBUG) {\n return;\n }\n const levelCode = Object.hasOwn(HF_LEVEL_CODES, level)\n ? HF_LEVEL_CODES[level]\n : HF_LEVEL_CODES.info;\n if (typeof message === 'string') {\n this.writeString(levelCode, message, args);\n return;\n }\n this.writeEntry(levelCode, message);\n }\n\n for(methodName: string): ILogger {\n return HfLogger.get(`${this.scope}-${methodName}`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../src/modules/logger/hf/logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAgB,SAAS,EAAE,eAAe,EAAkB,MAAM,WAAW,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAA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SAAS,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,UAAkB;QACpB,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC;IACrD,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { AbstractLogger } from '../base';\nimport { type ILogger, LogLevels, LoggerDebugGate, type TLogLevel } from '../common';\nimport { LogFormatUtility } from '../formatting';\nimport {\n BUFFER_SIZE,\n ENTRY_SIZE,\n HF_LEVEL_CODES,\n HF_MESSAGE_MAX_BYTES,\n HF_SCOPE_MAX_BYTES,\n MESSAGE_CACHE_CAP,\n OFFSET_LEVEL,\n OFFSET_MESSAGE,\n OFFSET_MESSAGE_LENGTH,\n OFFSET_SCOPE,\n OFFSET_SCOPE_LENGTH,\n type TRingState,\n} from './common';\nimport { HfLogRing } from './ring';\n\n/** Ring-buffer logger for hot paths; extends AbstractLogger, NOT BaseLogger - BaseLogger's string-sink plumbing is exactly the cost this implementation exists to avoid. */\nexport class HfLogger extends AbstractLogger {\n private static readonly textEncoder = new TextEncoder();\n private static readonly scopeCache = new Map<string, Uint8Array>();\n private static cache = new Map<string, HfLogger>();\n private static messageCache = new Map<string, Uint8Array>();\n\n private readonly scope: string;\n private readonly scopeBytes: Uint8Array;\n private readonly scopeLength: number;\n // Resolved once at construction (get() has already allocated the ring): saves a call and a null-check per log on a path budgeted in nanoseconds.\n private readonly ring: TRingState;\n\n private constructor(scope: string) {\n super();\n this.scope = scope;\n this.scopeBytes = HfLogger.encodeScope(scope);\n this.scopeLength = this.scopeBytes.length;\n this.ring = HfLogRing.get();\n }\n\n private static encodeScope(scope: string): Uint8Array {\n let bytes = HfLogger.scopeCache.get(scope);\n if (!bytes) {\n bytes = HfLogger.textEncoder.encode(scope).subarray(0, HF_SCOPE_MAX_BYTES);\n HfLogger.scopeCache.set(scope, bytes);\n }\n return bytes;\n }\n\n static get(scope: string): HfLogger {\n let logger = this.cache.get(scope);\n if (!logger) {\n logger = new HfLogger(scope); // first logger allocates the ring - never at import\n this.cache.set(scope, logger);\n }\n return logger;\n }\n\n /** Pre-encode a message at initialization time; the cache is FIFO-bounded so dynamic strings can't grow it without limit. */\n static encodeMessage(message: string): Uint8Array {\n const cached = this.messageCache.get(message);\n if (cached) {\n return cached;\n }\n\n const bytes = HfLogger.textEncoder.encode(message);\n if (this.messageCache.size >= MESSAGE_CACHE_CAP) {\n this.evictOldestMessage();\n }\n this.messageCache.set(message, bytes);\n return bytes;\n }\n\n private static evictOldestMessage(): void {\n const oldest = this.messageCache.keys().next().value;\n if (oldest === undefined) {\n return;\n }\n this.messageCache.delete(oldest);\n }\n\n private writeEntry(levelCode: number, messageBytes: Uint8Array): void {\n const ring = this.ring;\n const slot = ring.writeIndex++ & (BUFFER_SIZE - 1);\n const offset = slot * ENTRY_SIZE;\n ring.f64[offset >> 3] = performance.timeOrigin + performance.now();\n const bytes = ring.bytes;\n bytes[offset + OFFSET_LEVEL] = levelCode;\n bytes[offset + OFFSET_SCOPE_LENGTH] = this.scopeLength;\n bytes.set(this.scopeBytes, offset + OFFSET_SCOPE);\n const messageLength =\n messageBytes.length < HF_MESSAGE_MAX_BYTES ? messageBytes.length : HF_MESSAGE_MAX_BYTES;\n bytes[offset + OFFSET_MESSAGE_LENGTH] = messageLength;\n bytes.set(\n messageLength === messageBytes.length\n ? messageBytes\n : messageBytes.subarray(0, messageLength),\n offset + OFFSET_MESSAGE,\n );\n }\n\n private writeString(levelCode: number, message: string, args: Array<AnyType>): void {\n if (args.length > 0) {\n // Slow path, documented: args are formatted (deep inspection + redaction) - never dropped.\n this.writeEntry(\n levelCode,\n HfLogger.textEncoder.encode(LogFormatUtility.formatMessage({ message, args })),\n );\n return;\n }\n this.writeEntry(levelCode, HfLogger.encodeMessage(message));\n }\n\n debug(message: string, ...args: AnyType[]): void {\n if (!LoggerDebugGate.isOpen()) {\n return;\n }\n this.writeString(HF_LEVEL_CODES.debug, message, args);\n }\n\n info(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.info, message, args);\n }\n\n warn(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.warn, message, args);\n }\n\n error(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.error, message, args);\n }\n\n emerg(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.emerg, message, args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]): void;\n log(level: TLogLevel, messageBytes: Uint8Array): void;\n log(level: TLogLevel, message: string | Uint8Array, ...args: AnyType[]): void {\n if (level === LogLevels.DEBUG && !LoggerDebugGate.isOpen()) {\n return;\n }\n const levelCode = Object.hasOwn(HF_LEVEL_CODES, level)\n ? HF_LEVEL_CODES[level]\n : HF_LEVEL_CODES.info;\n if (typeof message === 'string') {\n this.writeString(levelCode, message, args);\n return;\n }\n this.writeEntry(levelCode, message);\n }\n\n for(methodName: string): ILogger {\n return HfLogger.get(`${this.scope}-${methodName}`);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC","sourcesContent":["export * from './base';\nexport * from './common';\nexport * from './factory';\nexport * from './formatting';\nexport * from './hf';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.utility.d.ts","sourceRoot":"","sources":["../../../src/utilities/module.utility.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAO9C,4LAA4L;AAC5L,qBAAa,aAAa;IACxB,0RAA0R;IAC1R,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAwD;IAE1F,OAAO,CAAC,MAAM,CAAC,cAAc;IAa7B,0PAA0P;IAC1P,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAI1D,MAAM,CAAC,cAAc,IAAI,MAAM;IAI/B,uHAAuH;IACvH,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB,OAAO,CAAC,MAAM,CAAC,IAAI;IAanB;;;;;;;;;OASG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,GAAG,IAAI;IAOjE;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;
|
|
1
|
+
{"version":3,"file":"module.utility.d.ts","sourceRoot":"","sources":["../../../src/utilities/module.utility.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,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
66
66
|
try {
|
|
67
67
|
const file = Bun.resolveSync(opts.module, this.getProjectRoot());
|
|
68
68
|
return path.isAbsolute(file) ? file : undefined;
|
|
69
|
+
// eslint-disable-next-line venizia/no-silent-catch -- documented contract: an unresolvable module is `undefined` and the caller falls back to a plain `import()`
|
|
69
70
|
}
|
|
70
71
|
catch {
|
|
71
72
|
return undefined;
|