@fgv/ts-utils 5.0.0-22 → 5.0.0-23
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 +307 -33
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/packlets/base/index.d.ts +0 -2
- package/lib/packlets/base/index.js +1 -25
- package/lib/packlets/base/result.d.ts +49 -0
- package/lib/packlets/base/result.js +36 -0
- package/lib/packlets/collections/collector.d.ts +9 -0
- package/lib/packlets/collections/collector.js +6 -0
- package/lib/packlets/collections/validatingCollector.d.ts +5 -1
- package/lib/packlets/hash/hashingNormalizer.js +4 -3
- package/lib/packlets/logging/index.d.ts +3 -0
- package/{src/packlets/hash/index.ts → lib/packlets/logging/index.js} +19 -3
- package/lib/packlets/logging/logReporter.d.ts +69 -0
- package/lib/packlets/logging/logReporter.js +72 -0
- package/lib/packlets/logging/logger.d.ts +183 -0
- package/lib/packlets/logging/logger.js +237 -0
- package/lib/test/unit/consoleLogger.test.d.ts +2 -0
- package/lib/test/unit/hashingNormalizerCollisions.test.d.ts +2 -0
- package/package.json +1 -1
- package/lib/packlets/base/logger.d.ts +0 -52
- package/lib/packlets/base/logger.js +0 -128
- package/src/index.ts +0 -63
- package/src/packlets/base/brand.ts +0 -28
- package/src/packlets/base/index.ts +0 -31
- package/src/packlets/base/logger.ts +0 -156
- package/src/packlets/base/mapResults.ts +0 -302
- package/src/packlets/base/messageAggregator.ts +0 -120
- package/src/packlets/base/normalize.ts +0 -144
- package/src/packlets/base/result.ts +0 -961
- package/src/packlets/base/utils.ts +0 -236
- package/src/packlets/collections/collectible.ts +0 -238
- package/src/packlets/collections/collector.ts +0 -273
- package/src/packlets/collections/collectorValidator.ts +0 -178
- package/src/packlets/collections/common.ts +0 -27
- package/src/packlets/collections/convertingCollector.ts +0 -223
- package/src/packlets/collections/convertingCollectorValidator.ts +0 -164
- package/src/packlets/collections/index.ts +0 -39
- package/src/packlets/collections/keyValueConverters.ts +0 -142
- package/src/packlets/collections/readonlyResultMap.ts +0 -99
- package/src/packlets/collections/resultMap.ts +0 -322
- package/src/packlets/collections/resultMapValidator.ts +0 -188
- package/src/packlets/collections/utils.ts +0 -33
- package/src/packlets/collections/validatingCollector.ts +0 -123
- package/src/packlets/collections/validatingConvertingCollector.ts +0 -113
- package/src/packlets/collections/validatingResultMap.ts +0 -94
- package/src/packlets/conversion/baseConverter.ts +0 -330
- package/src/packlets/conversion/converter.ts +0 -260
- package/src/packlets/conversion/converters.ts +0 -1039
- package/src/packlets/conversion/defaultingConverter.ts +0 -188
- package/src/packlets/conversion/index.ts +0 -30
- package/src/packlets/conversion/objectConverter.ts +0 -259
- package/src/packlets/conversion/stringConverter.ts +0 -165
- package/src/packlets/file-tree/directoryItem.ts +0 -84
- package/src/packlets/file-tree/fileItem.ts +0 -119
- package/src/packlets/file-tree/fileTree.ts +0 -152
- package/src/packlets/file-tree/fileTreeAccessors.ts +0 -176
- package/src/packlets/file-tree/fsTree.ts +0 -118
- package/src/packlets/file-tree/in-memory/inMemoryTree.ts +0 -171
- package/src/packlets/file-tree/in-memory/index.ts +0 -23
- package/src/packlets/file-tree/in-memory/treeBuilder.ts +0 -203
- package/src/packlets/file-tree/index.ts +0 -31
- package/src/packlets/hash/crcNormalizer.ts +0 -81
- package/src/packlets/hash/hashingNormalizer.ts +0 -102
- package/src/packlets/validation/array.ts +0 -84
- package/src/packlets/validation/boolean.ts +0 -63
- package/src/packlets/validation/classes.ts +0 -38
- package/src/packlets/validation/common.ts +0 -28
- package/src/packlets/validation/field.ts +0 -99
- package/src/packlets/validation/genericValidator.ts +0 -204
- package/src/packlets/validation/index.ts +0 -31
- package/src/packlets/validation/number.ts +0 -66
- package/src/packlets/validation/object.ts +0 -208
- package/src/packlets/validation/oneOf.ts +0 -78
- package/src/packlets/validation/string.ts +0 -66
- package/src/packlets/validation/traits.ts +0 -113
- package/src/packlets/validation/typeGuard.ts +0 -83
- package/src/packlets/validation/validator.ts +0 -157
- package/src/packlets/validation/validatorBase.ts +0 -66
- package/src/packlets/validation/validators.ts +0 -254
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NoOpLogger = exports.ConsoleLogger = exports.InMemoryLogger = exports.LoggerBase = void 0;
|
|
4
|
+
exports.shouldLog = shouldLog;
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (c) 2020 Erik Fortune
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
* copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
* SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
const base_1 = require("../base");
|
|
27
|
+
/**
|
|
28
|
+
* Compares two log levels.
|
|
29
|
+
* @param message - The first log level.
|
|
30
|
+
* @param reporter - The second log level.
|
|
31
|
+
* @returns `true` if the message should be logged, `false` if it should be suppressed.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
function shouldLog(message, reporter) {
|
|
35
|
+
if (reporter === 'all') {
|
|
36
|
+
return true; // 'all' logs everything, including 'quiet'
|
|
37
|
+
}
|
|
38
|
+
if (reporter === 'silent') {
|
|
39
|
+
return false; // 'silent' suppresses everything
|
|
40
|
+
}
|
|
41
|
+
if (message === 'quiet') {
|
|
42
|
+
return false; // 'quiet' messages only show when reporter is 'all'
|
|
43
|
+
}
|
|
44
|
+
switch (reporter) {
|
|
45
|
+
case 'error':
|
|
46
|
+
return message === 'error';
|
|
47
|
+
case 'warning':
|
|
48
|
+
return message === 'warning' || message === 'error';
|
|
49
|
+
case 'info':
|
|
50
|
+
return message !== 'detail';
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Abstract base class which implements {@link Logging.ILogger | ILogger}.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
class LoggerBase {
|
|
59
|
+
constructor(logLevel) {
|
|
60
|
+
/**
|
|
61
|
+
* {@inheritDoc Logging.ILogger.logLevel}
|
|
62
|
+
*/
|
|
63
|
+
this.logLevel = 'info';
|
|
64
|
+
this.logLevel = logLevel !== null && logLevel !== void 0 ? logLevel : 'info';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* {@inheritDoc Logging.ILogger.detail}
|
|
68
|
+
*/
|
|
69
|
+
detail(message, ...parameters) {
|
|
70
|
+
return this.log('detail', message, ...parameters);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* {@inheritDoc Logging.ILogger.info}
|
|
74
|
+
*/
|
|
75
|
+
info(message, ...parameters) {
|
|
76
|
+
return this.log('info', message, ...parameters);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* {@inheritDoc Logging.ILogger.warn}
|
|
80
|
+
*/
|
|
81
|
+
warn(message, ...parameters) {
|
|
82
|
+
return this.log('warning', message, ...parameters);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* {@inheritDoc Logging.ILogger.error}
|
|
86
|
+
*/
|
|
87
|
+
error(message, ...parameters) {
|
|
88
|
+
return this.log('error', message, ...parameters);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* {@inheritDoc Logging.ILogger.log}
|
|
92
|
+
*/
|
|
93
|
+
log(level, message, ...parameters) {
|
|
94
|
+
if (shouldLog(level, this.logLevel)) {
|
|
95
|
+
const formatted = this._format(message, ...parameters);
|
|
96
|
+
return this._log(formatted, level);
|
|
97
|
+
}
|
|
98
|
+
return this._suppressLog(level, message, ...parameters);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Formats a message and parameters into a string.
|
|
102
|
+
* @param message - The message to format.
|
|
103
|
+
* @param parameters - The parameters to format.
|
|
104
|
+
* @returns The formatted message.
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
_format(message, ...parameters) {
|
|
108
|
+
const raw = [message, ...parameters];
|
|
109
|
+
const filtered = raw.filter((m) => m !== undefined);
|
|
110
|
+
const strings = filtered.map((m) => m.toString());
|
|
111
|
+
const joined = strings.join('');
|
|
112
|
+
return joined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Inner method called for suppressed log messages.
|
|
116
|
+
*/
|
|
117
|
+
_suppressLog(__level, __message, ...__parameters) {
|
|
118
|
+
return (0, base_1.succeed)(undefined);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.LoggerBase = LoggerBase;
|
|
122
|
+
/**
|
|
123
|
+
* An in-memory logger that stores logged and suppressed messages.
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
class InMemoryLogger extends LoggerBase {
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new in-memory logger.
|
|
129
|
+
* @param logLevel - The level of logging to be used.
|
|
130
|
+
*/
|
|
131
|
+
constructor(logLevel) {
|
|
132
|
+
super(logLevel);
|
|
133
|
+
/**
|
|
134
|
+
* The messages that have been logged.
|
|
135
|
+
*/
|
|
136
|
+
this._logged = [];
|
|
137
|
+
/**
|
|
138
|
+
* The messages that have been suppressed.
|
|
139
|
+
*/
|
|
140
|
+
this._suppressed = [];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The messages that have been logged.
|
|
144
|
+
*/
|
|
145
|
+
get logged() {
|
|
146
|
+
return this._logged;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The messages that have been suppressed.
|
|
150
|
+
*/
|
|
151
|
+
get suppressed() {
|
|
152
|
+
return this._suppressed;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Clears the logged and suppressed messages.
|
|
156
|
+
*/
|
|
157
|
+
clear() {
|
|
158
|
+
this._logged = [];
|
|
159
|
+
this._suppressed = [];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* {@inheritDoc Logging.LoggerBase._log}
|
|
163
|
+
*/
|
|
164
|
+
_log(message, __level) {
|
|
165
|
+
this._logged.push(message);
|
|
166
|
+
return (0, base_1.succeed)(message);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* {@inheritDoc Logging.LoggerBase._suppressLog}
|
|
170
|
+
* @param level - The level of the message.
|
|
171
|
+
* @param message - The message to suppress.
|
|
172
|
+
* @param parameters - The parameters to suppress.
|
|
173
|
+
* @returns `Success` with `undefined` if the message is suppressed.
|
|
174
|
+
*/
|
|
175
|
+
_suppressLog(level, message, ...parameters) {
|
|
176
|
+
const formatted = this._format(message, ...parameters);
|
|
177
|
+
this._suppressed.push(formatted);
|
|
178
|
+
return (0, base_1.succeed)(undefined);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.InMemoryLogger = InMemoryLogger;
|
|
182
|
+
/**
|
|
183
|
+
* A console logger that outputs messages to the console.
|
|
184
|
+
* @public
|
|
185
|
+
*/
|
|
186
|
+
class ConsoleLogger extends LoggerBase {
|
|
187
|
+
/**
|
|
188
|
+
* Creates a new console logger.
|
|
189
|
+
* @param logLevel - The level of logging to be used.
|
|
190
|
+
*/
|
|
191
|
+
constructor(logLevel) {
|
|
192
|
+
super(logLevel);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* {@inheritDoc Logging.LoggerBase._log}
|
|
196
|
+
*/
|
|
197
|
+
_log(message, level) {
|
|
198
|
+
switch (level) {
|
|
199
|
+
case 'error':
|
|
200
|
+
console.error(message);
|
|
201
|
+
break;
|
|
202
|
+
case 'warning':
|
|
203
|
+
console.warn(message);
|
|
204
|
+
break;
|
|
205
|
+
case 'info':
|
|
206
|
+
console.info(message);
|
|
207
|
+
break;
|
|
208
|
+
default:
|
|
209
|
+
console.log(message);
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
return (0, base_1.succeed)(message);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.ConsoleLogger = ConsoleLogger;
|
|
216
|
+
/**
|
|
217
|
+
* A no-op {@link Logging.LoggerBase | LoggerBase} that does not log anything.
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
class NoOpLogger extends LoggerBase {
|
|
221
|
+
/**
|
|
222
|
+
* Creates a new no-op logger.
|
|
223
|
+
* @param logLevel - The level of logging to be used.
|
|
224
|
+
*/
|
|
225
|
+
constructor(logLevel) {
|
|
226
|
+
super(logLevel);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* {@inheritDoc Logging.LoggerBase._log}
|
|
230
|
+
*/
|
|
231
|
+
_log(message, __level) {
|
|
232
|
+
// no-op
|
|
233
|
+
return (0, base_1.succeed)(message);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
exports.NoOpLogger = NoOpLogger;
|
|
237
|
+
//# sourceMappingURL=logger.js.map
|
package/package.json
CHANGED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Failure, Success } from './result';
|
|
2
|
-
/**
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export type LogLevel = 'detail' | 'info' | 'warning' | 'error' | 'silent';
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface Logger {
|
|
10
|
-
log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
11
|
-
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
12
|
-
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
13
|
-
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
14
|
-
warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
15
|
-
error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export declare abstract class LoggerBase {
|
|
21
|
-
logLevel: LogLevel;
|
|
22
|
-
constructor(logLevel?: LogLevel);
|
|
23
|
-
detail(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
24
|
-
info(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
25
|
-
warn(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
26
|
-
warnAndFail<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
27
|
-
error<T>(message?: unknown, ...parameters: unknown[]): Failure<T>;
|
|
28
|
-
log(message?: unknown, ...parameters: unknown[]): Success<string | undefined>;
|
|
29
|
-
protected _format(message?: unknown, ...parameters: unknown[]): string;
|
|
30
|
-
protected _innerSilent(__message: string): Success<string | undefined>;
|
|
31
|
-
protected abstract _innerLog(message: string): Success<string | undefined>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* @public
|
|
35
|
-
*/
|
|
36
|
-
export declare class InMemoryLogger extends LoggerBase {
|
|
37
|
-
protected _messages: string[];
|
|
38
|
-
protected _silent: string[];
|
|
39
|
-
constructor(logLevel?: LogLevel);
|
|
40
|
-
get messages(): string[];
|
|
41
|
-
get silent(): string[];
|
|
42
|
-
clear(): void;
|
|
43
|
-
protected _innerLog(message: string): Success<string | undefined>;
|
|
44
|
-
protected _innerSilent(message: string): Success<string | undefined>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export declare class NoOpLogger extends LoggerBase {
|
|
50
|
-
protected _innerLog(message: string): Success<string | undefined>;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoOpLogger = exports.InMemoryLogger = exports.LoggerBase = 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 result_1 = require("./result");
|
|
26
|
-
/**
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
class LoggerBase {
|
|
30
|
-
constructor(logLevel) {
|
|
31
|
-
this.logLevel = 'info';
|
|
32
|
-
this.logLevel = logLevel !== null && logLevel !== void 0 ? logLevel : 'info';
|
|
33
|
-
}
|
|
34
|
-
detail(message, ...parameters) {
|
|
35
|
-
if (this.logLevel === 'detail') {
|
|
36
|
-
return this.log(message, parameters);
|
|
37
|
-
}
|
|
38
|
-
return (0, result_1.succeed)(undefined);
|
|
39
|
-
}
|
|
40
|
-
info(message, ...parameters) {
|
|
41
|
-
if (this.logLevel === 'detail' || this.logLevel === 'info') {
|
|
42
|
-
return this.log(message, parameters);
|
|
43
|
-
}
|
|
44
|
-
return (0, result_1.succeed)(undefined);
|
|
45
|
-
}
|
|
46
|
-
warn(message, ...parameters) {
|
|
47
|
-
if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
|
|
48
|
-
return this.log(message, parameters);
|
|
49
|
-
}
|
|
50
|
-
return (0, result_1.succeed)(undefined);
|
|
51
|
-
}
|
|
52
|
-
warnAndFail(message, ...parameters) {
|
|
53
|
-
var _a;
|
|
54
|
-
const formatted = this._format(message, ...parameters);
|
|
55
|
-
if (this.logLevel !== 'error' && this.logLevel !== 'silent') {
|
|
56
|
-
const result = this.log(formatted);
|
|
57
|
-
return (0, result_1.fail)((_a = result.value) !== null && _a !== void 0 ? _a : formatted);
|
|
58
|
-
}
|
|
59
|
-
return (0, result_1.fail)(formatted);
|
|
60
|
-
}
|
|
61
|
-
error(message, ...parameters) {
|
|
62
|
-
var _a;
|
|
63
|
-
const formatted = this._format(message, ...parameters);
|
|
64
|
-
if (this.logLevel !== 'silent') {
|
|
65
|
-
const result = this.log(formatted);
|
|
66
|
-
return (0, result_1.fail)((_a = result.value) !== null && _a !== void 0 ? _a : formatted);
|
|
67
|
-
}
|
|
68
|
-
return (0, result_1.fail)(formatted);
|
|
69
|
-
}
|
|
70
|
-
log(message, ...parameters) {
|
|
71
|
-
const messageString = this._format(message, ...parameters);
|
|
72
|
-
if (this.logLevel === 'silent') {
|
|
73
|
-
return this._innerSilent(messageString);
|
|
74
|
-
}
|
|
75
|
-
return this._innerLog(messageString);
|
|
76
|
-
}
|
|
77
|
-
_format(message, ...parameters) {
|
|
78
|
-
const raw = [message, ...parameters];
|
|
79
|
-
const filtered = raw.filter((m) => m !== undefined);
|
|
80
|
-
const strings = filtered.map((m) => m.toString());
|
|
81
|
-
const joined = strings.join('');
|
|
82
|
-
return joined;
|
|
83
|
-
}
|
|
84
|
-
_innerSilent(__message) {
|
|
85
|
-
return (0, result_1.succeed)(undefined);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.LoggerBase = LoggerBase;
|
|
89
|
-
/**
|
|
90
|
-
* @public
|
|
91
|
-
*/
|
|
92
|
-
class InMemoryLogger extends LoggerBase {
|
|
93
|
-
constructor(logLevel) {
|
|
94
|
-
super(logLevel);
|
|
95
|
-
this._messages = [];
|
|
96
|
-
this._silent = [];
|
|
97
|
-
}
|
|
98
|
-
get messages() {
|
|
99
|
-
return this._messages;
|
|
100
|
-
}
|
|
101
|
-
get silent() {
|
|
102
|
-
return this._silent;
|
|
103
|
-
}
|
|
104
|
-
clear() {
|
|
105
|
-
this._messages = [];
|
|
106
|
-
this._silent = [];
|
|
107
|
-
}
|
|
108
|
-
_innerLog(message) {
|
|
109
|
-
this._messages.push(message);
|
|
110
|
-
return (0, result_1.succeed)(message);
|
|
111
|
-
}
|
|
112
|
-
_innerSilent(message) {
|
|
113
|
-
this._silent.push(message);
|
|
114
|
-
return (0, result_1.succeed)(undefined);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
exports.InMemoryLogger = InMemoryLogger;
|
|
118
|
-
/**
|
|
119
|
-
* @public
|
|
120
|
-
*/
|
|
121
|
-
class NoOpLogger extends LoggerBase {
|
|
122
|
-
_innerLog(message) {
|
|
123
|
-
// no-op
|
|
124
|
-
return (0, result_1.succeed)(message);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
exports.NoOpLogger = NoOpLogger;
|
|
128
|
-
//# sourceMappingURL=logger.js.map
|
package/src/index.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import * as Collections from './packlets/collections';
|
|
24
|
-
import * as Conversion from './packlets/conversion';
|
|
25
|
-
import * as Hash from './packlets/hash';
|
|
26
|
-
import * as FileTree from './packlets/file-tree';
|
|
27
|
-
import * as Validation from './packlets/validation';
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
Collector,
|
|
31
|
-
ICollectible,
|
|
32
|
-
ConvertingCollector,
|
|
33
|
-
IReadOnlyResultMap,
|
|
34
|
-
ResultMap,
|
|
35
|
-
ValidatingCollector,
|
|
36
|
-
ValidatingConvertingCollector,
|
|
37
|
-
ValidatingResultMap
|
|
38
|
-
} from './packlets/collections';
|
|
39
|
-
import { Converter, Converters, ObjectConverter, StringConverter } from './packlets/conversion';
|
|
40
|
-
import { Validator, Validators } from './packlets/validation';
|
|
41
|
-
|
|
42
|
-
export * from './packlets/base';
|
|
43
|
-
export {
|
|
44
|
-
Collections,
|
|
45
|
-
Collector,
|
|
46
|
-
ConvertingCollector,
|
|
47
|
-
Conversion,
|
|
48
|
-
Converter,
|
|
49
|
-
Converters,
|
|
50
|
-
FileTree,
|
|
51
|
-
Hash,
|
|
52
|
-
ICollectible,
|
|
53
|
-
IReadOnlyResultMap,
|
|
54
|
-
ObjectConverter,
|
|
55
|
-
ResultMap,
|
|
56
|
-
StringConverter,
|
|
57
|
-
ValidatingCollector,
|
|
58
|
-
ValidatingConvertingCollector,
|
|
59
|
-
ValidatingResultMap,
|
|
60
|
-
Validation,
|
|
61
|
-
Validator,
|
|
62
|
-
Validators
|
|
63
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Helper type to brand a simple type to prevent inappropriate use
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
-
export type Brand<T, B> = T & { __brand: B };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2020 Erik Fortune
|
|
3
|
-
*
|
|
4
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
* in the Software without restriction, including without limitation the rights
|
|
7
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
* furnished to do so, subject to the following conditions:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
* copies or substantial portions of the Software.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
* SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import * as Logging from './logger';
|
|
24
|
-
|
|
25
|
-
export * from './brand';
|
|
26
|
-
export * from './mapResults';
|
|
27
|
-
export * from './messageAggregator';
|
|
28
|
-
export { Normalizer } from './normalize';
|
|
29
|
-
export * from './result';
|
|
30
|
-
export * from './utils';
|
|
31
|
-
export { Logging };
|