@fgv/ts-utils 5.0.0-25 → 5.0.0-27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ts-utils.d.ts +47 -10
- package/dist/tsdoc-metadata.json +1 -1
- package/eslint.config.js +37 -0
- package/lib/packlets/base/result.d.ts +10 -6
- package/lib/packlets/base/result.js +8 -6
- package/lib/packlets/conversion/baseConverter.js +0 -1
- package/lib/packlets/conversion/converters.js +0 -2
- package/lib/packlets/conversion/objectConverter.js +1 -2
- package/lib/packlets/logging/logReporter.d.ts +21 -2
- package/lib/packlets/logging/logReporter.js +46 -4
- package/lib/packlets/logging/logger.d.ts +16 -2
- package/lib/packlets/logging/logger.js +7 -0
- package/lib/packlets/validation/object.js +0 -1
- package/package.json +10 -10
package/dist/ts-utils.d.ts
CHANGED
|
@@ -575,6 +575,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
575
575
|
constructor(logLevel?: ReporterLogLevel);
|
|
576
576
|
/**
|
|
577
577
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
578
|
+
* @internal
|
|
578
579
|
*/
|
|
579
580
|
protected _log(message: string, level: MessageLogLevel): Success<string | undefined>;
|
|
580
581
|
}
|
|
@@ -1103,7 +1104,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1103
1104
|
/**
|
|
1104
1105
|
* {@inheritdoc IResult.report}
|
|
1105
1106
|
*/
|
|
1106
|
-
report(reporter
|
|
1107
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
1107
1108
|
orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;
|
|
1108
1109
|
orThrow(cb: ErrorFormatter): never;
|
|
1109
1110
|
/**
|
|
@@ -1195,7 +1196,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1195
1196
|
/**
|
|
1196
1197
|
* {@inheritdoc IResult.report}
|
|
1197
1198
|
*/
|
|
1198
|
-
report(reporter
|
|
1199
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
1199
1200
|
/**
|
|
1200
1201
|
* Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
|
|
1201
1202
|
* optional detail.
|
|
@@ -1440,7 +1441,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
1440
1441
|
/**
|
|
1441
1442
|
* {@inheritdoc IResult.report}
|
|
1442
1443
|
*/
|
|
1443
|
-
report(reporter
|
|
1444
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
1444
1445
|
/**
|
|
1445
1446
|
* Get a 'friendly' string representation of this object.
|
|
1446
1447
|
* @remarks
|
|
@@ -2293,7 +2294,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2293
2294
|
* @public
|
|
2294
2295
|
*/
|
|
2295
2296
|
declare interface ILogReporterCreateParams<T, TD = unknown> {
|
|
2296
|
-
logger
|
|
2297
|
+
logger?: ILogger;
|
|
2297
2298
|
valueFormatter?: LogValueFormatter<T, TD>;
|
|
2298
2299
|
messageFormatter?: LogMessageFormatter<TD>;
|
|
2299
2300
|
}
|
|
@@ -2363,12 +2364,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2363
2364
|
declare class InMemoryLogger extends LoggerBase {
|
|
2364
2365
|
/**
|
|
2365
2366
|
* The messages that have been logged.
|
|
2367
|
+
* @internal
|
|
2366
2368
|
*/
|
|
2367
|
-
|
|
2369
|
+
private _logged;
|
|
2368
2370
|
/**
|
|
2369
2371
|
* The messages that have been suppressed.
|
|
2372
|
+
* @internal
|
|
2370
2373
|
*/
|
|
2371
|
-
|
|
2374
|
+
private _suppressed;
|
|
2372
2375
|
/**
|
|
2373
2376
|
* Creates a new in-memory logger.
|
|
2374
2377
|
* @param logLevel - The level of logging to be used.
|
|
@@ -2388,6 +2391,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2388
2391
|
clear(): void;
|
|
2389
2392
|
/**
|
|
2390
2393
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
2394
|
+
* @internal
|
|
2391
2395
|
*/
|
|
2392
2396
|
protected _log(message: string, __level: MessageLogLevel): Success<string | undefined>;
|
|
2393
2397
|
/**
|
|
@@ -2396,6 +2400,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2396
2400
|
* @param message - The message to suppress.
|
|
2397
2401
|
* @param parameters - The parameters to suppress.
|
|
2398
2402
|
* @returns `Success` with `undefined` if the message is suppressed.
|
|
2403
|
+
* @internal
|
|
2399
2404
|
*/
|
|
2400
2405
|
protected _suppressLog(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<undefined>;
|
|
2401
2406
|
}
|
|
@@ -2772,7 +2777,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2772
2777
|
* @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.
|
|
2773
2778
|
* @param options - The {@link IResultReportOptions | options} for reporting the result.
|
|
2774
2779
|
*/
|
|
2775
|
-
report(reporter
|
|
2780
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
2776
2781
|
}
|
|
2777
2782
|
|
|
2778
2783
|
/**
|
|
@@ -2817,7 +2822,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2817
2822
|
* Options for reporting a result.
|
|
2818
2823
|
* @public
|
|
2819
2824
|
*/
|
|
2820
|
-
export declare interface IResultReportOptions {
|
|
2825
|
+
export declare interface IResultReportOptions<TD = unknown> {
|
|
2821
2826
|
/**
|
|
2822
2827
|
* The level of reporting to be used for failure results. Default is 'error'.
|
|
2823
2828
|
*/
|
|
@@ -2826,6 +2831,10 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
2826
2831
|
* The level of reporting to be used for success results. Default is 'quiet'.
|
|
2827
2832
|
*/
|
|
2828
2833
|
success?: MessageLogLevel;
|
|
2834
|
+
/**
|
|
2835
|
+
* The error formatter to be used for reporting an error result.
|
|
2836
|
+
*/
|
|
2837
|
+
message?: ErrorFormatter<TD>;
|
|
2829
2838
|
}
|
|
2830
2839
|
|
|
2831
2840
|
/**
|
|
@@ -3052,8 +3061,16 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3052
3061
|
protected _format(message?: unknown, ...parameters: unknown[]): string;
|
|
3053
3062
|
/**
|
|
3054
3063
|
* Inner method called for suppressed log messages.
|
|
3064
|
+
* @public
|
|
3055
3065
|
*/
|
|
3056
3066
|
protected _suppressLog(__level: MessageLogLevel, __message?: unknown, ...__parameters: unknown[]): Success<undefined>;
|
|
3067
|
+
/**
|
|
3068
|
+
* Inner method called for logged messages. Should be implemented by derived classes.
|
|
3069
|
+
* @param message - The message to log.
|
|
3070
|
+
* @param level - The {@link MessageLogLevel | level} of the message.
|
|
3071
|
+
* @returns `Success` with the logged message, or `Success` with `undefined` if the message is suppressed.
|
|
3072
|
+
* @public
|
|
3073
|
+
*/
|
|
3057
3074
|
protected abstract _log(message: string, level: MessageLogLevel): Success<string | undefined>;
|
|
3058
3075
|
}
|
|
3059
3076
|
|
|
@@ -3086,14 +3103,26 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3086
3103
|
* @public
|
|
3087
3104
|
*/
|
|
3088
3105
|
declare class LogReporter<T, TD = unknown> implements ILogger, IResultReporter<T, TD> {
|
|
3106
|
+
/**
|
|
3107
|
+
* The logger to wrap.
|
|
3108
|
+
* @internal
|
|
3109
|
+
*/
|
|
3089
3110
|
protected readonly _logger: ILogger;
|
|
3111
|
+
/**
|
|
3112
|
+
* The formatter to use for values.
|
|
3113
|
+
* @internal
|
|
3114
|
+
*/
|
|
3090
3115
|
protected readonly _valueFormatter: LogValueFormatter<T, TD>;
|
|
3116
|
+
/**
|
|
3117
|
+
* The formatter to use for messages.
|
|
3118
|
+
* @internal
|
|
3119
|
+
*/
|
|
3091
3120
|
protected readonly _messageFormatter: LogMessageFormatter<TD>;
|
|
3092
3121
|
/**
|
|
3093
3122
|
* Creates a new {@link Logging.LogReporter | LogReporter}.
|
|
3094
3123
|
* @param params - The parameters for creating the {@link Logging.LogReporter | LogReporter}.
|
|
3095
3124
|
*/
|
|
3096
|
-
constructor(params
|
|
3125
|
+
constructor(params?: ILogReporterCreateParams<T, TD>);
|
|
3097
3126
|
/**
|
|
3098
3127
|
* {@inheritDoc Logging.ILogger.logLevel}
|
|
3099
3128
|
*/
|
|
@@ -3126,6 +3155,13 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3126
3155
|
* {@inheritDoc IResultReporter.reportFailure}
|
|
3127
3156
|
*/
|
|
3128
3157
|
reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;
|
|
3158
|
+
/**
|
|
3159
|
+
* Generic method to try to format an object for logging.
|
|
3160
|
+
* @param value - The value to format.
|
|
3161
|
+
* @param detail - The detail to format.
|
|
3162
|
+
* @returns
|
|
3163
|
+
*/
|
|
3164
|
+
static tryFormatObject<T = unknown, TD = unknown>(value: T, detail?: TD): string;
|
|
3129
3165
|
}
|
|
3130
3166
|
|
|
3131
3167
|
/**
|
|
@@ -3335,6 +3371,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
3335
3371
|
constructor(logLevel?: ReporterLogLevel);
|
|
3336
3372
|
/**
|
|
3337
3373
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
3374
|
+
* @internal
|
|
3338
3375
|
*/
|
|
3339
3376
|
protected _log(message: string, __level: MessageLogLevel): Success<string | undefined>;
|
|
3340
3377
|
}
|
|
@@ -4609,7 +4646,7 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
|
|
|
4609
4646
|
/**
|
|
4610
4647
|
* {@inheritdoc IResult.report}
|
|
4611
4648
|
*/
|
|
4612
|
-
report(reporter
|
|
4649
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
4613
4650
|
/**
|
|
4614
4651
|
* Creates a {@link Success | Success<T>} with the supplied value.
|
|
4615
4652
|
* @param value - The value to be returned.
|
package/dist/tsdoc-metadata.json
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// ESLint 9 flat config for ts-utils
|
|
2
|
+
const nodeProfile = require('@rushstack/eslint-config/flat/profile/node');
|
|
3
|
+
const packletsPlugin = require('@rushstack/eslint-config/flat/mixins/packlets');
|
|
4
|
+
const tsdocPlugin = require('@rushstack/eslint-config/flat/mixins/tsdoc');
|
|
5
|
+
|
|
6
|
+
module.exports = [
|
|
7
|
+
...nodeProfile,
|
|
8
|
+
packletsPlugin,
|
|
9
|
+
...tsdocPlugin,
|
|
10
|
+
{
|
|
11
|
+
// Override specific rules if needed
|
|
12
|
+
rules: {
|
|
13
|
+
'@rushstack/packlets/mechanics': 'warn',
|
|
14
|
+
|
|
15
|
+
// Tighten naming conventions for interface properties
|
|
16
|
+
'@typescript-eslint/naming-convention': [
|
|
17
|
+
'warn',
|
|
18
|
+
// Keep all the base rules from rushstack but add stricter property rules
|
|
19
|
+
{
|
|
20
|
+
selector: 'property',
|
|
21
|
+
format: ['camelCase', 'UPPER_CASE'],
|
|
22
|
+
leadingUnderscore: 'allow',
|
|
23
|
+
filter: {
|
|
24
|
+
// Only allow quoted identifiers that truly need special chars (not just hyphens)
|
|
25
|
+
regex: '^__',
|
|
26
|
+
match: false
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
selector: 'method',
|
|
31
|
+
format: ['camelCase', 'PascalCase'],
|
|
32
|
+
leadingUnderscore: 'allow'
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
];
|
|
@@ -50,7 +50,7 @@ export type MessageLogLevel = 'quiet' | 'detail' | 'info' | 'warning' | 'error';
|
|
|
50
50
|
* Options for reporting a result.
|
|
51
51
|
* @public
|
|
52
52
|
*/
|
|
53
|
-
export interface IResultReportOptions {
|
|
53
|
+
export interface IResultReportOptions<TD = unknown> {
|
|
54
54
|
/**
|
|
55
55
|
* The level of reporting to be used for failure results. Default is 'error'.
|
|
56
56
|
*/
|
|
@@ -59,6 +59,10 @@ export interface IResultReportOptions {
|
|
|
59
59
|
* The level of reporting to be used for success results. Default is 'quiet'.
|
|
60
60
|
*/
|
|
61
61
|
success?: MessageLogLevel;
|
|
62
|
+
/**
|
|
63
|
+
* The error formatter to be used for reporting an error result.
|
|
64
|
+
*/
|
|
65
|
+
message?: ErrorFormatter<TD>;
|
|
62
66
|
}
|
|
63
67
|
/**
|
|
64
68
|
* Interface for reporting a result.
|
|
@@ -269,7 +273,7 @@ export interface IResult<T> {
|
|
|
269
273
|
* @param reporter - The {@link IResultReporter | reporter} to which the result will be reported.
|
|
270
274
|
* @param options - The {@link IResultReportOptions | options} for reporting the result.
|
|
271
275
|
*/
|
|
272
|
-
report(reporter
|
|
276
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
273
277
|
}
|
|
274
278
|
/**
|
|
275
279
|
* Reports a successful {@link IResult | result} from some operation and the
|
|
@@ -359,7 +363,7 @@ export declare class Success<T> implements IResult<T> {
|
|
|
359
363
|
/**
|
|
360
364
|
* {@inheritdoc IResult.report}
|
|
361
365
|
*/
|
|
362
|
-
report(reporter
|
|
366
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
363
367
|
/**
|
|
364
368
|
* Creates a {@link Success | Success<T>} with the supplied value.
|
|
365
369
|
* @param value - The value to be returned.
|
|
@@ -455,7 +459,7 @@ export declare class Failure<T> implements IResult<T> {
|
|
|
455
459
|
/**
|
|
456
460
|
* {@inheritdoc IResult.report}
|
|
457
461
|
*/
|
|
458
|
-
report(reporter
|
|
462
|
+
report(reporter?: IResultReporter<T>, options?: IResultReportOptions): this;
|
|
459
463
|
/**
|
|
460
464
|
* Get a 'friendly' string representation of this object.
|
|
461
465
|
* @remarks
|
|
@@ -581,7 +585,7 @@ export declare class DetailedSuccess<T, TD> extends Success<T> {
|
|
|
581
585
|
/**
|
|
582
586
|
* {@inheritdoc IResult.report}
|
|
583
587
|
*/
|
|
584
|
-
report(reporter
|
|
588
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
585
589
|
/**
|
|
586
590
|
* Creates a {@link DetailedSuccess | DetailedSuccess<T, TD>} with the supplied value and
|
|
587
591
|
* optional detail.
|
|
@@ -647,7 +651,7 @@ export declare class DetailedFailure<T, TD> extends Failure<T> {
|
|
|
647
651
|
/**
|
|
648
652
|
* {@inheritdoc IResult.report}
|
|
649
653
|
*/
|
|
650
|
-
report(reporter
|
|
654
|
+
report(reporter?: IResultReporter<T, TD>, options?: IResultReportOptions<TD>): this;
|
|
651
655
|
orThrow(logOrFormat?: IResultLogger<TD> | ErrorFormatter<TD>): never;
|
|
652
656
|
orThrow(cb: ErrorFormatter): never;
|
|
653
657
|
/**
|
|
@@ -136,7 +136,7 @@ class Success {
|
|
|
136
136
|
report(reporter, options) {
|
|
137
137
|
var _a;
|
|
138
138
|
const level = (_a = options === null || options === void 0 ? void 0 : options.success) !== null && _a !== void 0 ? _a : 'quiet';
|
|
139
|
-
reporter.reportSuccess(level, this._value);
|
|
139
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportSuccess(level, this._value);
|
|
140
140
|
return this;
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
@@ -260,9 +260,10 @@ class Failure {
|
|
|
260
260
|
* {@inheritdoc IResult.report}
|
|
261
261
|
*/
|
|
262
262
|
report(reporter, options) {
|
|
263
|
-
var _a;
|
|
263
|
+
var _a, _b, _c;
|
|
264
264
|
const level = (_a = options === null || options === void 0 ? void 0 : options.failure) !== null && _a !== void 0 ? _a : 'error';
|
|
265
|
-
|
|
265
|
+
const message = (_c = (_b = options === null || options === void 0 ? void 0 : options.message) === null || _b === void 0 ? void 0 : _b.call(options, this._message)) !== null && _c !== void 0 ? _c : this._message;
|
|
266
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message);
|
|
266
267
|
return this;
|
|
267
268
|
}
|
|
268
269
|
/**
|
|
@@ -400,7 +401,7 @@ class DetailedSuccess extends Success {
|
|
|
400
401
|
report(reporter, options) {
|
|
401
402
|
var _a;
|
|
402
403
|
const level = (_a = options === null || options === void 0 ? void 0 : options.success) !== null && _a !== void 0 ? _a : 'quiet';
|
|
403
|
-
reporter.reportSuccess(level, this._value, this._detail);
|
|
404
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportSuccess(level, this._value, this._detail);
|
|
404
405
|
return this;
|
|
405
406
|
}
|
|
406
407
|
/**
|
|
@@ -483,9 +484,10 @@ class DetailedFailure extends Failure {
|
|
|
483
484
|
* {@inheritdoc IResult.report}
|
|
484
485
|
*/
|
|
485
486
|
report(reporter, options) {
|
|
486
|
-
var _a;
|
|
487
|
+
var _a, _b, _c;
|
|
487
488
|
const level = (_a = options === null || options === void 0 ? void 0 : options.failure) !== null && _a !== void 0 ? _a : 'error';
|
|
488
|
-
|
|
489
|
+
const message = (_c = (_b = options === null || options === void 0 ? void 0 : options.message) === null || _b === void 0 ? void 0 : _b.call(options, this._message, this._detail)) !== null && _c !== void 0 ? _c : this._message;
|
|
490
|
+
reporter === null || reporter === void 0 ? void 0 : reporter.reportFailure(level, message, this._detail);
|
|
489
491
|
return this;
|
|
490
492
|
}
|
|
491
493
|
orThrow(logOrFormat) {
|
|
@@ -580,7 +580,6 @@ function discriminatedObject(discriminatorProp, converters) {
|
|
|
580
580
|
function transform(properties) {
|
|
581
581
|
return new baseConverter_1.BaseConverter((from, __self, context) => {
|
|
582
582
|
// eslint bug thinks key is used before defined
|
|
583
|
-
// eslint-disable-next-line no-use-before-define
|
|
584
583
|
const converted = {};
|
|
585
584
|
const errors = [];
|
|
586
585
|
for (const key in properties) {
|
|
@@ -620,7 +619,6 @@ function transform(properties) {
|
|
|
620
619
|
function transformObject(destinationFields, options) {
|
|
621
620
|
return new baseConverter_1.BaseConverter((from, __self, context) => {
|
|
622
621
|
// eslint bug thinks key is used before defined
|
|
623
|
-
// eslint-disable-next-line no-use-before-define
|
|
624
622
|
const converted = {};
|
|
625
623
|
const errors = [];
|
|
626
624
|
const used = new Set(options === null || options === void 0 ? void 0 : options.ignore);
|
|
@@ -104,9 +104,8 @@ class ObjectConverter extends baseConverter_1.BaseConverter {
|
|
|
104
104
|
return new ObjectConverter(this.fields, options)._with(this._traits());
|
|
105
105
|
}
|
|
106
106
|
static _convert(from, context, fields, options) {
|
|
107
|
-
var _a;
|
|
108
107
|
// eslint bug thinks key is used before defined
|
|
109
|
-
|
|
108
|
+
var _a;
|
|
110
109
|
const converted = {};
|
|
111
110
|
const errors = [];
|
|
112
111
|
for (const key in fields) {
|
|
@@ -15,7 +15,7 @@ export type LogMessageFormatter<TD = unknown> = (message: string, detail?: TD) =
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
export interface ILogReporterCreateParams<T, TD = unknown> {
|
|
18
|
-
logger
|
|
18
|
+
logger?: ILogger;
|
|
19
19
|
valueFormatter?: LogValueFormatter<T, TD>;
|
|
20
20
|
messageFormatter?: LogMessageFormatter<TD>;
|
|
21
21
|
}
|
|
@@ -25,14 +25,26 @@ export interface ILogReporterCreateParams<T, TD = unknown> {
|
|
|
25
25
|
* @public
|
|
26
26
|
*/
|
|
27
27
|
export declare class LogReporter<T, TD = unknown> implements ILogger, IResultReporter<T, TD> {
|
|
28
|
+
/**
|
|
29
|
+
* The logger to wrap.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
28
32
|
protected readonly _logger: ILogger;
|
|
33
|
+
/**
|
|
34
|
+
* The formatter to use for values.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
29
37
|
protected readonly _valueFormatter: LogValueFormatter<T, TD>;
|
|
38
|
+
/**
|
|
39
|
+
* The formatter to use for messages.
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
30
42
|
protected readonly _messageFormatter: LogMessageFormatter<TD>;
|
|
31
43
|
/**
|
|
32
44
|
* Creates a new {@link Logging.LogReporter | LogReporter}.
|
|
33
45
|
* @param params - The parameters for creating the {@link Logging.LogReporter | LogReporter}.
|
|
34
46
|
*/
|
|
35
|
-
constructor(params
|
|
47
|
+
constructor(params?: ILogReporterCreateParams<T, TD>);
|
|
36
48
|
/**
|
|
37
49
|
* {@inheritDoc Logging.ILogger.logLevel}
|
|
38
50
|
*/
|
|
@@ -65,5 +77,12 @@ export declare class LogReporter<T, TD = unknown> implements ILogger, IResultRep
|
|
|
65
77
|
* {@inheritDoc IResultReporter.reportFailure}
|
|
66
78
|
*/
|
|
67
79
|
reportFailure(level: MessageLogLevel, message: string, detail?: TD): void;
|
|
80
|
+
/**
|
|
81
|
+
* Generic method to try to format an object for logging.
|
|
82
|
+
* @param value - The value to format.
|
|
83
|
+
* @param detail - The detail to format.
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
static tryFormatObject<T = unknown, TD = unknown>(value: T, detail?: TD): string;
|
|
68
87
|
}
|
|
69
88
|
//# sourceMappingURL=logReporter.d.ts.map
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LogReporter = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020 Erik Fortune
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
const logger_1 = require("./logger");
|
|
4
26
|
/**
|
|
5
27
|
* Abstract base class which wraps an existing {@link Logging.ILogger | ILogger} to implement
|
|
6
28
|
* both {@link Logging.ILogger | ILogger} and {@link IResultReporter | IResultReporter}.
|
|
@@ -12,10 +34,12 @@ class LogReporter {
|
|
|
12
34
|
* @param params - The parameters for creating the {@link Logging.LogReporter | LogReporter}.
|
|
13
35
|
*/
|
|
14
36
|
constructor(params) {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.
|
|
37
|
+
var _a, _b, _c;
|
|
38
|
+
/* c8 ignore next 1 */
|
|
39
|
+
params = params !== null && params !== void 0 ? params : {};
|
|
40
|
+
this._logger = (_a = params.logger) !== null && _a !== void 0 ? _a : new logger_1.NoOpLogger();
|
|
41
|
+
this._valueFormatter = (_b = params.valueFormatter) !== null && _b !== void 0 ? _b : LogReporter.tryFormatObject;
|
|
42
|
+
this._messageFormatter = (_c = params.messageFormatter) !== null && _c !== void 0 ? _c : ((message, __detail) => message);
|
|
19
43
|
}
|
|
20
44
|
/**
|
|
21
45
|
* {@inheritDoc Logging.ILogger.logLevel}
|
|
@@ -67,6 +91,24 @@ class LogReporter {
|
|
|
67
91
|
const formatted = this._messageFormatter(message, detail);
|
|
68
92
|
this.log(level, formatted);
|
|
69
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Generic method to try to format an object for logging.
|
|
96
|
+
* @param value - The value to format.
|
|
97
|
+
* @param detail - The detail to format.
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
static tryFormatObject(value, detail) {
|
|
101
|
+
const message = String(value);
|
|
102
|
+
if (message === '[object Object]') {
|
|
103
|
+
try {
|
|
104
|
+
return JSON.stringify(value);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return message;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return message;
|
|
111
|
+
}
|
|
70
112
|
}
|
|
71
113
|
exports.LogReporter = LogReporter;
|
|
72
114
|
//# sourceMappingURL=logReporter.js.map
|
|
@@ -103,8 +103,16 @@ export declare abstract class LoggerBase implements ILogger {
|
|
|
103
103
|
protected _format(message?: unknown, ...parameters: unknown[]): string;
|
|
104
104
|
/**
|
|
105
105
|
* Inner method called for suppressed log messages.
|
|
106
|
+
* @public
|
|
106
107
|
*/
|
|
107
108
|
protected _suppressLog(__level: MessageLogLevel, __message?: unknown, ...__parameters: unknown[]): Success<undefined>;
|
|
109
|
+
/**
|
|
110
|
+
* Inner method called for logged messages. Should be implemented by derived classes.
|
|
111
|
+
* @param message - The message to log.
|
|
112
|
+
* @param level - The {@link MessageLogLevel | level} of the message.
|
|
113
|
+
* @returns `Success` with the logged message, or `Success` with `undefined` if the message is suppressed.
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
108
116
|
protected abstract _log(message: string, level: MessageLogLevel): Success<string | undefined>;
|
|
109
117
|
}
|
|
110
118
|
/**
|
|
@@ -114,12 +122,14 @@ export declare abstract class LoggerBase implements ILogger {
|
|
|
114
122
|
export declare class InMemoryLogger extends LoggerBase {
|
|
115
123
|
/**
|
|
116
124
|
* The messages that have been logged.
|
|
125
|
+
* @internal
|
|
117
126
|
*/
|
|
118
|
-
|
|
127
|
+
private _logged;
|
|
119
128
|
/**
|
|
120
129
|
* The messages that have been suppressed.
|
|
130
|
+
* @internal
|
|
121
131
|
*/
|
|
122
|
-
|
|
132
|
+
private _suppressed;
|
|
123
133
|
/**
|
|
124
134
|
* Creates a new in-memory logger.
|
|
125
135
|
* @param logLevel - The level of logging to be used.
|
|
@@ -139,6 +149,7 @@ export declare class InMemoryLogger extends LoggerBase {
|
|
|
139
149
|
clear(): void;
|
|
140
150
|
/**
|
|
141
151
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
152
|
+
* @internal
|
|
142
153
|
*/
|
|
143
154
|
protected _log(message: string, __level: MessageLogLevel): Success<string | undefined>;
|
|
144
155
|
/**
|
|
@@ -147,6 +158,7 @@ export declare class InMemoryLogger extends LoggerBase {
|
|
|
147
158
|
* @param message - The message to suppress.
|
|
148
159
|
* @param parameters - The parameters to suppress.
|
|
149
160
|
* @returns `Success` with `undefined` if the message is suppressed.
|
|
161
|
+
* @internal
|
|
150
162
|
*/
|
|
151
163
|
protected _suppressLog(level: MessageLogLevel, message?: unknown, ...parameters: unknown[]): Success<undefined>;
|
|
152
164
|
}
|
|
@@ -162,6 +174,7 @@ export declare class ConsoleLogger extends LoggerBase {
|
|
|
162
174
|
constructor(logLevel?: ReporterLogLevel);
|
|
163
175
|
/**
|
|
164
176
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
177
|
+
* @internal
|
|
165
178
|
*/
|
|
166
179
|
protected _log(message: string, level: MessageLogLevel): Success<string | undefined>;
|
|
167
180
|
}
|
|
@@ -177,6 +190,7 @@ export declare class NoOpLogger extends LoggerBase {
|
|
|
177
190
|
constructor(logLevel?: ReporterLogLevel);
|
|
178
191
|
/**
|
|
179
192
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
193
|
+
* @internal
|
|
180
194
|
*/
|
|
181
195
|
protected _log(message: string, __level: MessageLogLevel): Success<string | undefined>;
|
|
182
196
|
}
|
|
@@ -113,6 +113,7 @@ class LoggerBase {
|
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
115
|
* Inner method called for suppressed log messages.
|
|
116
|
+
* @public
|
|
116
117
|
*/
|
|
117
118
|
_suppressLog(__level, __message, ...__parameters) {
|
|
118
119
|
return (0, base_1.succeed)(undefined);
|
|
@@ -132,10 +133,12 @@ class InMemoryLogger extends LoggerBase {
|
|
|
132
133
|
super(logLevel);
|
|
133
134
|
/**
|
|
134
135
|
* The messages that have been logged.
|
|
136
|
+
* @internal
|
|
135
137
|
*/
|
|
136
138
|
this._logged = [];
|
|
137
139
|
/**
|
|
138
140
|
* The messages that have been suppressed.
|
|
141
|
+
* @internal
|
|
139
142
|
*/
|
|
140
143
|
this._suppressed = [];
|
|
141
144
|
}
|
|
@@ -160,6 +163,7 @@ class InMemoryLogger extends LoggerBase {
|
|
|
160
163
|
}
|
|
161
164
|
/**
|
|
162
165
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
166
|
+
* @internal
|
|
163
167
|
*/
|
|
164
168
|
_log(message, __level) {
|
|
165
169
|
this._logged.push(message);
|
|
@@ -171,6 +175,7 @@ class InMemoryLogger extends LoggerBase {
|
|
|
171
175
|
* @param message - The message to suppress.
|
|
172
176
|
* @param parameters - The parameters to suppress.
|
|
173
177
|
* @returns `Success` with `undefined` if the message is suppressed.
|
|
178
|
+
* @internal
|
|
174
179
|
*/
|
|
175
180
|
_suppressLog(level, message, ...parameters) {
|
|
176
181
|
const formatted = this._format(message, ...parameters);
|
|
@@ -193,6 +198,7 @@ class ConsoleLogger extends LoggerBase {
|
|
|
193
198
|
}
|
|
194
199
|
/**
|
|
195
200
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
201
|
+
* @internal
|
|
196
202
|
*/
|
|
197
203
|
_log(message, level) {
|
|
198
204
|
switch (level) {
|
|
@@ -227,6 +233,7 @@ class NoOpLogger extends LoggerBase {
|
|
|
227
233
|
}
|
|
228
234
|
/**
|
|
229
235
|
* {@inheritDoc Logging.LoggerBase._log}
|
|
236
|
+
* @internal
|
|
230
237
|
*/
|
|
231
238
|
_log(message, __level) {
|
|
232
239
|
// no-op
|
|
@@ -114,7 +114,6 @@ class ObjectValidator extends validatorBase_1.ValidatorBase {
|
|
|
114
114
|
return (0, base_1.fail)('source is not an object');
|
|
115
115
|
}
|
|
116
116
|
// eslint bug thinks key is used before defined
|
|
117
|
-
// eslint-disable-next-line no-use-before-define
|
|
118
117
|
const converted = {};
|
|
119
118
|
const errors = [];
|
|
120
119
|
for (const key in this._innerValidators) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fgv/ts-utils",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-27",
|
|
4
4
|
"description": "Assorted Typescript Utilities",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "dist/ts-utils.d.ts",
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
"@types/luxon": "^3.7.1",
|
|
24
24
|
"@types/mustache": "^4.2.5",
|
|
25
25
|
"@types/node": "^20.14.9",
|
|
26
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
27
|
-
"@typescript-eslint/parser": "^
|
|
28
|
-
"eslint": "^
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "^8.42.0",
|
|
27
|
+
"@typescript-eslint/parser": "^8.42.0",
|
|
28
|
+
"eslint": "^9.35.0",
|
|
29
29
|
"eslint-plugin-import": "^2.32.0",
|
|
30
30
|
"eslint-plugin-node": "^11.1.0",
|
|
31
|
-
"eslint-plugin-promise": "^
|
|
31
|
+
"eslint-plugin-promise": "^7.2.1",
|
|
32
32
|
"jest": "^29.7.0",
|
|
33
33
|
"jest-extended": "^4.0.2",
|
|
34
34
|
"jest-matcher-utils": "^29.7.0",
|
|
35
|
-
"rimraf": "^
|
|
35
|
+
"rimraf": "^6.0.1",
|
|
36
36
|
"ts-jest": "^29.4.1",
|
|
37
37
|
"ts-node": "^10.9.2",
|
|
38
38
|
"typescript": "5.8.3",
|
|
39
|
-
"eslint-plugin-n": "^
|
|
39
|
+
"eslint-plugin-n": "^17.21.3",
|
|
40
40
|
"jest-snapshot": "~29.7.0",
|
|
41
|
-
"@rushstack/heft": "0.74.
|
|
42
|
-
"@rushstack/heft-node-rig": "2.9.
|
|
41
|
+
"@rushstack/heft": "0.74.4",
|
|
42
|
+
"@rushstack/heft-node-rig": "2.9.5",
|
|
43
43
|
"@rushstack/eslint-config": "4.4.0",
|
|
44
44
|
"@types/heft-jest": "1.0.6",
|
|
45
|
-
"@rushstack/heft-jest-plugin": "0.16.
|
|
45
|
+
"@rushstack/heft-jest-plugin": "0.16.13",
|
|
46
46
|
"eslint-plugin-tsdoc": "~0.4.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|