@reliverse/relinka 1.1.7 → 1.1.8
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-npm/components/anykey/index.js +57 -77
- package/dist-npm/components/block/block.js +48 -61
- package/dist-npm/components/checkbox/index.js +178 -211
- package/dist-npm/components/confirm/confirm-main.js +85 -122
- package/dist-npm/components/confirm/confirm-three.js +24 -27
- package/dist-npm/components/confirm/index.js +36 -45
- package/dist-npm/components/core/Separator.js +15 -17
- package/dist-npm/components/core/create-prompt.js +101 -124
- package/dist-npm/components/core/errors.js +19 -15
- package/dist-npm/components/core/hook-engine.js +91 -120
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +16 -6
- package/dist-npm/components/core/lines.js +45 -54
- package/dist-npm/components/core/make-theme.js +21 -30
- package/dist-npm/components/core/position.js +27 -23
- package/dist-npm/components/core/promise-polyfill.js +11 -14
- package/dist-npm/components/core/screen-manager.js +59 -74
- package/dist-npm/components/core/theme.js +22 -32
- package/dist-npm/components/core/use-effect.js +9 -15
- package/dist-npm/components/core/use-keypress.js +19 -23
- package/dist-npm/components/core/use-memo.js +10 -16
- package/dist-npm/components/core/use-pagination.js +33 -32
- package/dist-npm/components/core/use-prefix.js +40 -38
- package/dist-npm/components/core/use-ref.js +2 -5
- package/dist-npm/components/core/use-state.js +15 -23
- package/dist-npm/components/core/useKeyPress.js +14 -17
- package/dist-npm/components/core/usePromptState.js +8 -14
- package/dist-npm/components/core/utils.js +7 -16
- package/dist-npm/components/date/date.js +173 -204
- package/dist-npm/components/editor/index.js +71 -92
- package/dist-npm/components/expand/index.js +96 -124
- package/dist-npm/components/figures/index.js +283 -294
- package/dist-npm/components/input/index.js +61 -87
- package/dist-npm/components/input/text-main.js +97 -124
- package/dist-npm/components/input/text.js +24 -28
- package/dist-npm/components/instance/basic.js +17 -25
- package/dist-npm/components/instance/browser.js +14 -18
- package/dist-npm/components/instance/reporter/basic.js +46 -65
- package/dist-npm/components/instance/reporter/browser.js +44 -47
- package/dist-npm/components/instance/reporter/fancy.js +83 -96
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +52 -62
- package/dist-npm/components/mono/monoTwo.js +35 -49
- package/dist-npm/components/multiselect/group-multiselect.js +55 -71
- package/dist-npm/components/multiselect/multi-select-two.js +97 -130
- package/dist-npm/components/multiselect/multi-select.js +43 -49
- package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
- package/dist-npm/components/multiselect/multiselect-main.js +158 -145
- package/dist-npm/components/multiselect/num-multi-select.js +97 -130
- package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
- package/dist-npm/components/next-steps/next-steps.js +23 -25
- package/dist-npm/components/number/index.js +78 -112
- package/dist-npm/components/number/number-main.js +95 -2
- package/dist-npm/components/password/index.js +54 -73
- package/dist-npm/components/password/password-main.js +119 -2
- package/dist-npm/components/password/password-three.js +26 -30
- package/dist-npm/components/progressbar/ProgressBar.js +45 -64
- package/dist-npm/components/progressbar/helper.js +33 -40
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +29 -44
- package/dist-npm/components/prompts/index.d.ts +1 -0
- package/dist-npm/components/prompts/index.js +46 -45
- package/dist-npm/components/prompts/prompt.js +211 -260
- package/dist-npm/components/prompts/promptTwo.js +561 -605
- package/dist-npm/components/prompts/relinka.js +237 -295
- package/dist-npm/components/range/range.js +247 -294
- package/dist-npm/components/rawlist/index.js +87 -107
- package/dist-npm/components/results/results.js +31 -37
- package/dist-npm/components/search/index.js +148 -193
- package/dist-npm/components/select/index.js +148 -186
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +124 -5
- package/dist-npm/components/select/select-key.js +24 -25
- package/dist-npm/components/select/select-main.d.ts +1 -0
- package/dist-npm/components/select/select-main.js +143 -133
- package/dist-npm/components/select/select-three.js +32 -36
- package/dist-npm/components/select/select-two.js +94 -87
- package/dist-npm/components/spinner/index.js +107 -136
- package/dist-npm/components/st-end/end.js +34 -26
- package/dist-npm/components/st-end/start.js +29 -15
- package/dist-npm/components/toggle/index.js +113 -137
- package/dist-npm/components/visual/animate/animate.js +53 -10
- package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
- package/dist-npm/main.js +1 -0
- package/dist-npm/testing/index.js +58 -83
- package/dist-npm/types/general.d.ts +1 -1
- package/dist-npm/types/general.js +0 -1
- package/dist-npm/types/index.js +2 -3
- package/dist-npm/types/keypress.js +35 -36
- package/dist-npm/types/readline.js +0 -1
- package/dist-npm/types/relinka.js +0 -1
- package/dist-npm/types/utils.js +0 -1
- package/dist-npm/utils/box.js +135 -137
- package/dist-npm/utils/color.js +65 -74
- package/dist-npm/utils/colorize.js +124 -156
- package/dist-npm/utils/component.js +532 -657
- package/dist-npm/utils/constants.js +64 -63
- package/dist-npm/utils/core.js +2 -3
- package/dist-npm/utils/decoder.js +244 -223
- package/dist-npm/utils/error.js +4 -9
- package/dist-npm/utils/errors.js +14 -4
- package/dist-npm/utils/format.js +19 -24
- package/dist-npm/utils/keypress.js +316 -414
- package/dist-npm/utils/log.js +11 -15
- package/dist-npm/utils/mapping.js +45 -52
- package/dist-npm/utils/messages.js +196 -183
- package/dist-npm/utils/platforms.js +16 -20
- package/dist-npm/utils/prompt-tmp.js +235 -286
- package/dist-npm/utils/prompt-two.js +235 -286
- package/dist-npm/utils/readline.js +5 -7
- package/dist-npm/utils/skeleton.js +130 -170
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +44 -58
- package/dist-npm/utils/terminal.js +23 -34
- package/dist-npm/utils/tree.js +30 -41
- package/dist-npm/utils/types.js +0 -1
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +36 -44
- package/package.json +14 -14
- package/dist-npm/mod.js +0 -2
- /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
|
@@ -1,338 +1,280 @@
|
|
|
1
|
-
import {defu} from
|
|
2
|
-
import {LogTypes} from
|
|
3
|
-
import {isLogObj} from
|
|
4
|
-
|
|
5
|
-
const {isArray} = Array;
|
|
6
|
-
const isNumber = (a) => typeof a === 'number';
|
|
7
|
-
const isString = (a) => typeof a === 'string';
|
|
8
|
-
const isFn = (a) => typeof a === 'function';
|
|
9
|
-
const maybeArray = (a) => isArray(a) ? a : [a];
|
|
1
|
+
import { defu } from "defu";
|
|
2
|
+
import { LogTypes } from "../../utils/constants.js";
|
|
3
|
+
import { isLogObj } from "../../utils/log.js";
|
|
10
4
|
let paused = false;
|
|
11
5
|
const queue = [];
|
|
12
|
-
|
|
13
6
|
export class Relinka {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
options;
|
|
8
|
+
_lastLog;
|
|
9
|
+
_mockFn;
|
|
17
10
|
constructor(options = {}) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
for (const type in types) {
|
|
36
|
-
const defaults = {
|
|
37
|
-
type,
|
|
38
|
-
...this.options.defaults,
|
|
39
|
-
...types[type],
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
this[type] = this._wrapLogFn(defaults);
|
|
43
|
-
this[type].raw = this._wrapLogFn(defaults, true);
|
|
11
|
+
const types = options.types || LogTypes;
|
|
12
|
+
this.options = defu(
|
|
13
|
+
{
|
|
14
|
+
...options,
|
|
15
|
+
defaults: { ...options.defaults },
|
|
16
|
+
level: _normalizeLogLevel(options.level, types),
|
|
17
|
+
reporters: [...options.reporters || []]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
types: LogTypes,
|
|
21
|
+
throttle: 1e3,
|
|
22
|
+
throttleMin: 5,
|
|
23
|
+
formatOptions: {
|
|
24
|
+
date: true,
|
|
25
|
+
colors: false,
|
|
26
|
+
compact: true
|
|
44
27
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
for (const type in types) {
|
|
31
|
+
const defaults = {
|
|
32
|
+
type,
|
|
33
|
+
...this.options.defaults,
|
|
34
|
+
...types[type]
|
|
35
|
+
};
|
|
36
|
+
this[type] = this._wrapLogFn(defaults);
|
|
37
|
+
this[type].raw = this._wrapLogFn(
|
|
38
|
+
defaults,
|
|
39
|
+
true
|
|
40
|
+
);
|
|
50
41
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return this.options.level;
|
|
42
|
+
if (this.options.mockFn) {
|
|
43
|
+
this.mockTypes();
|
|
54
44
|
}
|
|
55
|
-
|
|
45
|
+
this._lastLog = {};
|
|
46
|
+
}
|
|
47
|
+
get level() {
|
|
48
|
+
return this.options.level;
|
|
49
|
+
}
|
|
56
50
|
set level(level) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
this.options.level = _normalizeLogLevel(
|
|
52
|
+
level,
|
|
53
|
+
this.options.types,
|
|
54
|
+
this.options.level
|
|
55
|
+
);
|
|
56
|
+
}
|
|
60
57
|
prompt(message, opts) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return this.options.prompt(message, opts);
|
|
58
|
+
if (!this.options.prompt) {
|
|
59
|
+
throw new Error("prompt is not supported!");
|
|
66
60
|
}
|
|
67
|
-
|
|
61
|
+
return this.options.prompt(message, opts);
|
|
62
|
+
}
|
|
68
63
|
create(options) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
instance.mockTypes(this._mockFn);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return instance;
|
|
64
|
+
const instance = new Relinka({
|
|
65
|
+
...this.options,
|
|
66
|
+
...options
|
|
67
|
+
});
|
|
68
|
+
if (this._mockFn) {
|
|
69
|
+
instance.mockTypes(this._mockFn);
|
|
79
70
|
}
|
|
80
|
-
|
|
71
|
+
return instance;
|
|
72
|
+
}
|
|
81
73
|
withDefaults(defaults) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
return this.create({
|
|
75
|
+
...this.options,
|
|
76
|
+
defaults: {
|
|
77
|
+
...this.options.defaults,
|
|
78
|
+
...defaults
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
91
82
|
withTag(tag) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
83
|
+
return this.withDefaults({
|
|
84
|
+
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
|
85
|
+
});
|
|
86
|
+
}
|
|
97
87
|
addReporter(reporter) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
this.options.reporters.push(reporter);
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
102
91
|
removeReporter(reporter) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.options.reporters.splice(0);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return this;
|
|
92
|
+
if (reporter) {
|
|
93
|
+
const i = this.options.reporters.indexOf(reporter);
|
|
94
|
+
if (i >= 0) {
|
|
95
|
+
return this.options.reporters.splice(i, 1);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
this.options.reporters.splice(0);
|
|
114
99
|
}
|
|
115
|
-
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
116
102
|
setReporters(reporters) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.restoreStd();
|
|
129
|
-
}
|
|
130
|
-
|
|
103
|
+
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
wrapAll() {
|
|
107
|
+
this.wrapConsole();
|
|
108
|
+
this.wrapStd();
|
|
109
|
+
}
|
|
110
|
+
restoreAll() {
|
|
111
|
+
this.restoreConsole();
|
|
112
|
+
this.restoreStd();
|
|
113
|
+
}
|
|
131
114
|
wrapConsole() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
console[type] = this[type].raw;
|
|
138
|
-
}
|
|
115
|
+
for (const type in this.options.types) {
|
|
116
|
+
if (!console["__" + type]) {
|
|
117
|
+
console["__" + type] = console[type];
|
|
118
|
+
}
|
|
119
|
+
console[type] = this[type].raw;
|
|
139
120
|
}
|
|
140
|
-
|
|
121
|
+
}
|
|
141
122
|
restoreConsole() {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
123
|
+
for (const type in this.options.types) {
|
|
124
|
+
if (console["__" + type]) {
|
|
125
|
+
console[type] = console["__" + type];
|
|
126
|
+
delete console["__" + type];
|
|
127
|
+
}
|
|
148
128
|
}
|
|
149
|
-
|
|
129
|
+
}
|
|
150
130
|
wrapStd() {
|
|
151
|
-
|
|
152
|
-
|
|
131
|
+
this._wrapStream(this.options.stdout, "log");
|
|
132
|
+
this._wrapStream(this.options.stderr, "log");
|
|
133
|
+
}
|
|
134
|
+
_wrapStream(stream, type) {
|
|
135
|
+
if (!stream) {
|
|
136
|
+
return;
|
|
153
137
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (!stream) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (!stream.__write) {
|
|
161
|
-
stream.__write = stream.write;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
stream.write = (data) => {
|
|
165
|
-
this[type].raw(String(data).trim());
|
|
166
|
-
};
|
|
138
|
+
if (!stream.__write) {
|
|
139
|
+
stream.__write = stream.write;
|
|
167
140
|
}
|
|
168
|
-
|
|
141
|
+
stream.write = (data) => {
|
|
142
|
+
this[type].raw(String(data).trim());
|
|
143
|
+
};
|
|
144
|
+
}
|
|
169
145
|
restoreStd() {
|
|
170
|
-
|
|
171
|
-
|
|
146
|
+
this._restoreStream(this.options.stdout);
|
|
147
|
+
this._restoreStream(this.options.stderr);
|
|
148
|
+
}
|
|
149
|
+
_restoreStream(stream) {
|
|
150
|
+
if (!stream) {
|
|
151
|
+
return;
|
|
172
152
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (stream.__write) {
|
|
180
|
-
stream.write = stream.__write;
|
|
181
|
-
delete stream.__write;
|
|
182
|
-
}
|
|
153
|
+
if (stream.__write) {
|
|
154
|
+
stream.write = stream.__write;
|
|
155
|
+
delete stream.__write;
|
|
183
156
|
}
|
|
184
|
-
|
|
157
|
+
}
|
|
185
158
|
pauseLogs() {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
159
|
+
paused = true;
|
|
160
|
+
}
|
|
189
161
|
resumeLogs() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
item[0]._logFn(item[1], item[2]);
|
|
195
|
-
}
|
|
162
|
+
paused = false;
|
|
163
|
+
const _queue = queue.splice(0);
|
|
164
|
+
for (const item of _queue) {
|
|
165
|
+
item[0]._logFn(item[1], item[2]);
|
|
196
166
|
}
|
|
197
|
-
|
|
167
|
+
}
|
|
198
168
|
mockTypes(mockFn) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
for (const type in this.options.types) {
|
|
207
|
-
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
208
|
-
this[type].raw = this[type];
|
|
209
|
-
}
|
|
169
|
+
const _mockFn = mockFn || this.options.mockFn;
|
|
170
|
+
this._mockFn = _mockFn;
|
|
171
|
+
if (typeof _mockFn !== "function") {
|
|
172
|
+
return;
|
|
210
173
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (paused) {
|
|
215
|
-
queue.push([
|
|
216
|
-
this,
|
|
217
|
-
defaults,
|
|
218
|
-
args,
|
|
219
|
-
isRaw,
|
|
220
|
-
]);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return this._logFn(defaults, args, isRaw);
|
|
225
|
-
};
|
|
174
|
+
for (const type in this.options.types) {
|
|
175
|
+
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
176
|
+
this[type].raw = this[type];
|
|
226
177
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
241
|
-
Object.assign(logObj, args[0]);
|
|
242
|
-
} else {
|
|
243
|
-
logObj.args = args.slice();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (logObj.message) {
|
|
247
|
-
logObj.args.unshift(logObj.message);
|
|
248
|
-
delete logObj.message;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (logObj.additional) {
|
|
252
|
-
if (!Array.isArray(logObj.additional)) {
|
|
253
|
-
logObj.additional = logObj.additional.split('\n');
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
logObj.args.push('\n' + logObj.additional.join('\n'));
|
|
257
|
-
delete logObj.additional;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
logObj.type = isString(logObj.type) ? logObj.type.toLowerCase() : 'log';
|
|
261
|
-
if (!isString(logObj.tag))
|
|
262
|
-
logObj.tag = '';
|
|
263
|
-
|
|
264
|
-
const resolveLog = (newLog = false) => {
|
|
265
|
-
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
266
|
-
|
|
267
|
-
if (this._lastLog.object && repeated > 0) {
|
|
268
|
-
const args2 = this._lastLog.object.args.slice();
|
|
269
|
-
|
|
270
|
-
if (repeated > 1) {
|
|
271
|
-
args2.push(`(repeated ${repeated} times)`);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
this._log({ ...this._lastLog.object,
|
|
275
|
-
args: args2});
|
|
276
|
-
this._lastLog.count = 1;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (newLog) {
|
|
280
|
-
this._lastLog.object = logObj;
|
|
281
|
-
this._log(logObj);
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
clearTimeout(this._lastLog.timeout);
|
|
286
|
-
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
287
|
-
|
|
288
|
-
this._lastLog.time = logObj.date;
|
|
289
|
-
if (diffTime < this.options.throttle) {
|
|
290
|
-
try {
|
|
291
|
-
const serializedLog = JSON.stringify([
|
|
292
|
-
logObj.type,
|
|
293
|
-
logObj.tag,
|
|
294
|
-
logObj.args,
|
|
295
|
-
]);
|
|
296
|
-
|
|
297
|
-
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
298
|
-
|
|
299
|
-
this._lastLog.serialized = serializedLog;
|
|
300
|
-
if (isSameLog) {
|
|
301
|
-
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
302
|
-
if (this._lastLog.count > this.options.throttleMin) {
|
|
303
|
-
this._lastLog.timeout = setTimeout(resolveLog, this.options.throttle);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
} catch {}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
resolveLog(true);
|
|
178
|
+
}
|
|
179
|
+
_wrapLogFn(defaults, isRaw) {
|
|
180
|
+
return (...args) => {
|
|
181
|
+
if (paused) {
|
|
182
|
+
queue.push([this, defaults, args, isRaw]);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
return this._logFn(defaults, args, isRaw);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
_logFn(defaults, args, isRaw) {
|
|
189
|
+
if ((defaults.level || 0) > this.level) {
|
|
190
|
+
return false;
|
|
311
191
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
192
|
+
const logObj = {
|
|
193
|
+
date: new Date(),
|
|
194
|
+
args: [],
|
|
195
|
+
...defaults,
|
|
196
|
+
level: _normalizeLogLevel(defaults.level, this.options.types)
|
|
197
|
+
};
|
|
198
|
+
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
199
|
+
Object.assign(logObj, args[0]);
|
|
200
|
+
} else {
|
|
201
|
+
logObj.args = [...args];
|
|
319
202
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
203
|
+
if (logObj.message) {
|
|
204
|
+
logObj.args.unshift(logObj.message);
|
|
205
|
+
delete logObj.message;
|
|
323
206
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
207
|
+
if (logObj.additional) {
|
|
208
|
+
if (!Array.isArray(logObj.additional)) {
|
|
209
|
+
logObj.additional = logObj.additional.split("\n");
|
|
210
|
+
}
|
|
211
|
+
logObj.args.push("\n" + logObj.additional.join("\n"));
|
|
212
|
+
delete logObj.additional;
|
|
327
213
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
214
|
+
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
215
|
+
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
216
|
+
const resolveLog = (newLog = false) => {
|
|
217
|
+
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
218
|
+
if (this._lastLog.object && repeated > 0) {
|
|
219
|
+
const args2 = [...this._lastLog.object.args];
|
|
220
|
+
if (repeated > 1) {
|
|
221
|
+
args2.push(`(repeated ${repeated} times)`);
|
|
222
|
+
}
|
|
223
|
+
this._log({ ...this._lastLog.object, args: args2 });
|
|
224
|
+
this._lastLog.count = 1;
|
|
225
|
+
}
|
|
226
|
+
if (newLog) {
|
|
227
|
+
this._lastLog.object = logObj;
|
|
228
|
+
this._log(logObj);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
clearTimeout(this._lastLog.timeout);
|
|
232
|
+
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
233
|
+
this._lastLog.time = logObj.date;
|
|
234
|
+
if (diffTime < this.options.throttle) {
|
|
235
|
+
try {
|
|
236
|
+
const serializedLog = JSON.stringify([
|
|
237
|
+
logObj.type,
|
|
238
|
+
logObj.tag,
|
|
239
|
+
logObj.args
|
|
240
|
+
]);
|
|
241
|
+
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
242
|
+
this._lastLog.serialized = serializedLog;
|
|
243
|
+
if (isSameLog) {
|
|
244
|
+
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
245
|
+
if (this._lastLog.count > this.options.throttleMin) {
|
|
246
|
+
this._lastLog.timeout = setTimeout(
|
|
247
|
+
resolveLog,
|
|
248
|
+
this.options.throttle
|
|
249
|
+
);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} catch {
|
|
254
|
+
}
|
|
331
255
|
}
|
|
332
|
-
|
|
256
|
+
resolveLog(true);
|
|
257
|
+
}
|
|
258
|
+
_log(logObj) {
|
|
259
|
+
for (const reporter of this.options.reporters) {
|
|
260
|
+
reporter.log(logObj, {
|
|
261
|
+
options: this.options
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
267
|
+
if (input === void 0) {
|
|
333
268
|
return defaultLevel;
|
|
269
|
+
}
|
|
270
|
+
if (typeof input === "number") {
|
|
271
|
+
return input;
|
|
272
|
+
}
|
|
273
|
+
if (types[input] && types[input].level !== void 0) {
|
|
274
|
+
return types[input].level;
|
|
275
|
+
}
|
|
276
|
+
return defaultLevel;
|
|
334
277
|
}
|
|
335
|
-
|
|
336
278
|
Relinka.prototype.add = Relinka.prototype.addReporter;
|
|
337
279
|
Relinka.prototype.remove = Relinka.prototype.removeReporter;
|
|
338
280
|
Relinka.prototype.clear = Relinka.prototype.removeReporter;
|
|
@@ -341,5 +283,5 @@ Relinka.prototype.mock = Relinka.prototype.mockTypes;
|
|
|
341
283
|
Relinka.prototype.pause = Relinka.prototype.pauseLogs;
|
|
342
284
|
Relinka.prototype.resume = Relinka.prototype.resumeLogs;
|
|
343
285
|
export function createRelinka(options = {}) {
|
|
344
|
-
|
|
286
|
+
return new Relinka(options);
|
|
345
287
|
}
|