@naturalcycles/nodejs-lib 12.48.0 → 12.50.0
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/colors/colors.d.ts +6 -1
- package/dist/colors/colors.js +7 -7
- package/dist/stream/transform/transformLogProgress.js +7 -7
- package/dist/validation/ajv/ajvValidationError.js +0 -14
- package/dist/validation/joi/joi.validation.error.js +0 -14
- package/dist/validation/joi/joi.validation.util.js +1 -0
- package/package.json +1 -2
- package/src/colors/colors.ts +7 -5
- package/src/stream/transform/transformLogProgress.ts +9 -8
- package/src/validation/ajv/ajvValidationError.ts +0 -15
- package/src/validation/joi/joi.validation.error.ts +0 -15
- package/src/validation/joi/joi.validation.util.ts +1 -0
package/dist/colors/colors.d.ts
CHANGED
package/dist/colors/colors.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hasColors = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.hasColors = hasColors;
|
|
4
|
+
const tty = require("tty");
|
|
5
|
+
/**
|
|
6
|
+
* Based on: https://github.com/sindresorhus/yoctocolors/pull/5
|
|
7
|
+
*
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
exports.hasColors = !process.env['NO_COLOR'] && tty.WriteStream.prototype.hasColors();
|
|
@@ -8,7 +8,7 @@ const time_lib_1 = require("@naturalcycles/time-lib");
|
|
|
8
8
|
const colors_1 = require("../../colors");
|
|
9
9
|
const colors_2 = require("../../colors/colors");
|
|
10
10
|
const inspectOpt = {
|
|
11
|
-
colors:
|
|
11
|
+
colors: colors_2.hasColors,
|
|
12
12
|
breakLength: 300,
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
@@ -46,14 +46,14 @@ function transformLogProgress(opt = {}) {
|
|
|
46
46
|
return;
|
|
47
47
|
const mem = process.memoryUsage();
|
|
48
48
|
const now = Date.now();
|
|
49
|
-
const
|
|
50
|
-
const
|
|
49
|
+
const batchedProgress = progress * batchSize;
|
|
50
|
+
const lastRPS = (processedLastSecond * batchedProgress) / ((now - lastSecondStarted) / 1000) || 0;
|
|
51
|
+
const rpsTotal = Math.round(batchedProgress / ((now - started) / 1000)) || 0;
|
|
51
52
|
lastSecondStarted = now;
|
|
52
53
|
processedLastSecond = 0;
|
|
53
54
|
const rps10 = Math.round(sma.push(lastRPS));
|
|
54
55
|
if (mem.rss > peakRSS)
|
|
55
56
|
peakRSS = mem.rss;
|
|
56
|
-
const batchedProgress = progress * batchSize;
|
|
57
57
|
console.log((0, util_1.inspect)({
|
|
58
58
|
[final ? `${metric}_final` : metric]: batchedProgress,
|
|
59
59
|
...(extra ? extra(chunk, progress) : {}),
|
|
@@ -72,14 +72,14 @@ function transformLogProgress(opt = {}) {
|
|
|
72
72
|
: {}),
|
|
73
73
|
}, inspectOpt));
|
|
74
74
|
if (tenx) {
|
|
75
|
-
let perHour = Math.round((
|
|
75
|
+
let perHour = Math.round((batchedProgress * 1000 * 60 * 60) / (now - started)) || 0;
|
|
76
76
|
if (perHour > 900) {
|
|
77
77
|
perHour = Math.round(perHour / 1000) + 'K';
|
|
78
78
|
}
|
|
79
|
-
console.log(`${(0, colors_1.dimGrey)((0, time_lib_1.dayjs)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} so far to process ${(0, colors_1.yellow)(
|
|
79
|
+
console.log(`${(0, colors_1.dimGrey)((0, time_lib_1.dayjs)().toPretty())} ${(0, colors_1.white)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} so far to process ${(0, colors_1.yellow)(batchedProgress)} rows, ~${(0, colors_1.yellow)(perHour)}/hour`);
|
|
80
80
|
}
|
|
81
81
|
else if (final) {
|
|
82
|
-
console.log(`${(0, colors_1.boldWhite)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} to process ${(0, colors_1.yellow)(
|
|
82
|
+
console.log(`${(0, colors_1.boldWhite)(metric)} took ${(0, colors_1.yellow)((0, js_lib_1._since)(started))} to process ${(0, colors_1.yellow)(batchedProgress)} rows with total RPS of ${(0, colors_1.yellow)(rpsTotal)}`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -5,20 +5,6 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
class AjvValidationError extends js_lib_1.AppError {
|
|
6
6
|
constructor(message, data) {
|
|
7
7
|
super(message, data);
|
|
8
|
-
this.constructor = AjvValidationError;
|
|
9
|
-
this.__proto__ = AjvValidationError.prototype;
|
|
10
|
-
Object.defineProperty(this, 'name', {
|
|
11
|
-
value: this.constructor.name,
|
|
12
|
-
configurable: true,
|
|
13
|
-
});
|
|
14
|
-
if (Error.captureStackTrace) {
|
|
15
|
-
Error.captureStackTrace(this, this.constructor);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
Object.defineProperty(this, 'stack', {
|
|
19
|
-
value: new Error().stack, // eslint-disable-line unicorn/error-message
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
8
|
}
|
|
23
9
|
}
|
|
24
10
|
exports.AjvValidationError = AjvValidationError;
|
|
@@ -5,20 +5,6 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
class JoiValidationError extends js_lib_1.AppError {
|
|
6
6
|
constructor(message, data) {
|
|
7
7
|
super(message, data);
|
|
8
|
-
this.constructor = JoiValidationError;
|
|
9
|
-
this.__proto__ = JoiValidationError.prototype;
|
|
10
|
-
Object.defineProperty(this, 'name', {
|
|
11
|
-
value: this.constructor.name,
|
|
12
|
-
configurable: true,
|
|
13
|
-
});
|
|
14
|
-
if (Error.captureStackTrace) {
|
|
15
|
-
Error.captureStackTrace(this, this.constructor);
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
Object.defineProperty(this, 'stack', {
|
|
19
|
-
value: new Error().stack, // eslint-disable-line unicorn/error-message
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
8
|
}
|
|
23
9
|
}
|
|
24
10
|
exports.JoiValidationError = JoiValidationError;
|
|
@@ -130,6 +130,7 @@ function createError(value, err, objectName) {
|
|
|
130
130
|
// Make annotation non-enumerable, to not get it automatically printed,
|
|
131
131
|
// but still accessible
|
|
132
132
|
Object.defineProperty(data, 'annotation', {
|
|
133
|
+
writable: true,
|
|
133
134
|
configurable: true,
|
|
134
135
|
enumerable: false,
|
|
135
136
|
value: annotation,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.50.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"docs-serve": "vuepress dev docs",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
"move-file": "^2.0.0",
|
|
38
38
|
"nanoid": "^3.0.0",
|
|
39
39
|
"sanitize-html": "^2.5.2",
|
|
40
|
-
"supports-color": "^8.0.0",
|
|
41
40
|
"through2-concurrent": "^2.0.0",
|
|
42
41
|
"yargs": "^17.0.0"
|
|
43
42
|
},
|
package/src/colors/colors.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import * as tty from 'tty'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Based on: https://github.com/sindresorhus/yoctocolors/pull/5
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export const hasColors = !process.env['NO_COLOR'] && tty.WriteStream.prototype.hasColors()
|
|
@@ -104,7 +104,7 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
const inspectOpt: InspectOptions = {
|
|
107
|
-
colors: hasColors
|
|
107
|
+
colors: hasColors,
|
|
108
108
|
breakLength: 300,
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -163,16 +163,16 @@ export function transformLogProgress<IN = any>(
|
|
|
163
163
|
const mem = process.memoryUsage()
|
|
164
164
|
|
|
165
165
|
const now = Date.now()
|
|
166
|
-
const
|
|
167
|
-
const
|
|
166
|
+
const batchedProgress = progress * batchSize
|
|
167
|
+
const lastRPS =
|
|
168
|
+
(processedLastSecond * batchedProgress) / ((now - lastSecondStarted) / 1000) || 0
|
|
169
|
+
const rpsTotal = Math.round(batchedProgress / ((now - started) / 1000)) || 0
|
|
168
170
|
lastSecondStarted = now
|
|
169
171
|
processedLastSecond = 0
|
|
170
172
|
|
|
171
173
|
const rps10 = Math.round(sma.push(lastRPS))
|
|
172
174
|
if (mem.rss > peakRSS) peakRSS = mem.rss
|
|
173
175
|
|
|
174
|
-
const batchedProgress = progress * batchSize
|
|
175
|
-
|
|
176
176
|
console.log(
|
|
177
177
|
inspect(
|
|
178
178
|
{
|
|
@@ -197,7 +197,8 @@ export function transformLogProgress<IN = any>(
|
|
|
197
197
|
)
|
|
198
198
|
|
|
199
199
|
if (tenx) {
|
|
200
|
-
let perHour: number | string =
|
|
200
|
+
let perHour: number | string =
|
|
201
|
+
Math.round((batchedProgress * 1000 * 60 * 60) / (now - started)) || 0
|
|
201
202
|
if (perHour > 900) {
|
|
202
203
|
perHour = Math.round(perHour / 1000) + 'K'
|
|
203
204
|
}
|
|
@@ -205,12 +206,12 @@ export function transformLogProgress<IN = any>(
|
|
|
205
206
|
console.log(
|
|
206
207
|
`${dimGrey(dayjs().toPretty())} ${white(metric)} took ${yellow(
|
|
207
208
|
_since(started),
|
|
208
|
-
)} so far to process ${yellow(
|
|
209
|
+
)} so far to process ${yellow(batchedProgress)} rows, ~${yellow(perHour)}/hour`,
|
|
209
210
|
)
|
|
210
211
|
} else if (final) {
|
|
211
212
|
console.log(
|
|
212
213
|
`${boldWhite(metric)} took ${yellow(_since(started))} to process ${yellow(
|
|
213
|
-
|
|
214
|
+
batchedProgress,
|
|
214
215
|
)} rows with total RPS of ${yellow(rpsTotal)}`,
|
|
215
216
|
)
|
|
216
217
|
}
|
|
@@ -10,20 +10,5 @@ export interface AjvValidationErrorData extends ErrorData {
|
|
|
10
10
|
export class AjvValidationError extends AppError<AjvValidationErrorData> {
|
|
11
11
|
constructor(message: string, data: AjvValidationErrorData) {
|
|
12
12
|
super(message, data)
|
|
13
|
-
|
|
14
|
-
this.constructor = AjvValidationError
|
|
15
|
-
;(this as any).__proto__ = AjvValidationError.prototype
|
|
16
|
-
Object.defineProperty(this, 'name', {
|
|
17
|
-
value: this.constructor.name,
|
|
18
|
-
configurable: true,
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
if (Error.captureStackTrace) {
|
|
22
|
-
Error.captureStackTrace(this, this.constructor)
|
|
23
|
-
} else {
|
|
24
|
-
Object.defineProperty(this, 'stack', {
|
|
25
|
-
value: new Error().stack, // eslint-disable-line unicorn/error-message
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
13
|
}
|
|
29
14
|
}
|
|
@@ -28,20 +28,5 @@ export interface JoiValidationErrorData extends ErrorData {
|
|
|
28
28
|
export class JoiValidationError extends AppError<JoiValidationErrorData> {
|
|
29
29
|
constructor(message: string, data: JoiValidationErrorData) {
|
|
30
30
|
super(message, data)
|
|
31
|
-
|
|
32
|
-
this.constructor = JoiValidationError
|
|
33
|
-
;(this as any).__proto__ = JoiValidationError.prototype
|
|
34
|
-
Object.defineProperty(this, 'name', {
|
|
35
|
-
value: this.constructor.name,
|
|
36
|
-
configurable: true,
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
if (Error.captureStackTrace) {
|
|
40
|
-
Error.captureStackTrace(this, this.constructor)
|
|
41
|
-
} else {
|
|
42
|
-
Object.defineProperty(this, 'stack', {
|
|
43
|
-
value: new Error().stack, // eslint-disable-line unicorn/error-message
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
31
|
}
|
|
47
32
|
}
|
|
@@ -172,6 +172,7 @@ function createError(value: any, err: ValidationError, objectName?: string): Joi
|
|
|
172
172
|
// Make annotation non-enumerable, to not get it automatically printed,
|
|
173
173
|
// but still accessible
|
|
174
174
|
Object.defineProperty(data, 'annotation', {
|
|
175
|
+
writable: true,
|
|
175
176
|
configurable: true,
|
|
176
177
|
enumerable: false,
|
|
177
178
|
value: annotation,
|