@naturalcycles/nodejs-lib 13.34.5 → 13.35.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/stream/transform/transformThrottle.js +12 -7
- package/dist/validation/joi/joi.shared.schemas.d.ts +2 -0
- package/dist/validation/joi/joi.shared.schemas.js +5 -1
- package/package.json +1 -1
- package/src/stream/transform/transformThrottle.ts +14 -6
- package/src/validation/joi/joi.shared.schemas.ts +7 -0
|
@@ -49,7 +49,7 @@ function transformThrottle(opt) {
|
|
|
49
49
|
// console.log('pausing now after', {item, count})
|
|
50
50
|
paused = (0, js_lib_1.pDefer)();
|
|
51
51
|
if (debug) {
|
|
52
|
-
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${(0, js_lib_1.
|
|
52
|
+
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${(0, js_lib_1._since)(start)}, will pause for ${(0, js_lib_1._ms)(interval * 1000 - (Date.now() - start))}`);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
cb(null, item); // pass the item through
|
|
@@ -60,15 +60,20 @@ function transformThrottle(opt) {
|
|
|
60
60
|
},
|
|
61
61
|
});
|
|
62
62
|
function onInterval(transform) {
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (paused) {
|
|
64
|
+
if (debug) {
|
|
65
|
+
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle resumed`);
|
|
66
|
+
}
|
|
67
|
+
paused.resolve();
|
|
68
|
+
paused = undefined;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (debug) {
|
|
72
|
+
console.log(`${js_lib_1.localTime.now().toPretty()} transformThrottle passed ${count} (of max ${throughput}) items in ${(0, js_lib_1._since)(start)}`);
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
count = 0;
|
|
69
76
|
start = Date.now();
|
|
70
77
|
timeout = setTimeout(() => onInterval(transform), interval * 1000);
|
|
71
|
-
paused.resolve();
|
|
72
|
-
paused = undefined;
|
|
73
78
|
}
|
|
74
79
|
}
|
|
@@ -14,6 +14,8 @@ export declare const dateStringSchema: StringSchema<string>;
|
|
|
14
14
|
export declare const binarySchema: import("joi").BinarySchema<Buffer>;
|
|
15
15
|
export declare const dateObjectSchema: ObjectSchema<any>;
|
|
16
16
|
export declare const dateIntervalStringSchema: StringSchema<string>;
|
|
17
|
+
export declare const DATE_TIME_STRING_REGEX: RegExp;
|
|
18
|
+
export declare const dateTimeStringSchema: StringSchema<string>;
|
|
17
19
|
/**
|
|
18
20
|
* Allows all values of a String Enum.
|
|
19
21
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uuidSchema = exports.macAddressSchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.ianaTimezoneSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
|
|
3
|
+
exports.uuidSchema = exports.macAddressSchema = exports.baseDBEntitySchema = exports.ipAddressSchema = exports.ianaTimezoneSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_REGEX = exports.emailSchema = exports.verSchema = exports.unixTimestampMillis2000Schema = exports.unixTimestampMillisSchema = exports.unixTimestamp2000Schema = exports.unixTimestampSchema = exports.slugSchema = exports.SLUG_REGEX = exports.idBase64UrlSchema = exports.idBase64Schema = exports.idBase62Schema = exports.idSchema = exports.jwtSchema = exports.JWT_REGEX = exports.base64UrlSchema = exports.base64Schema = exports.base62Schema = exports.BASE64URL_REGEX = exports.BASE64_REGEX = exports.BASE62_REGEX = exports.anyObjectSchema = exports.anySchema = exports.urlSchema = exports.numberEnumKeySchema = exports.numberEnumValueSchema = exports.stringEnumKeySchema = exports.stringEnumValueSchema = exports.dateTimeStringSchema = exports.DATE_TIME_STRING_REGEX = exports.dateIntervalStringSchema = exports.dateObjectSchema = exports.binarySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchemaTyped = exports.numberSchema = exports.stringSchemaTyped = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = void 0;
|
|
4
4
|
exports.arraySchema = arraySchema;
|
|
5
5
|
exports.objectSchema = objectSchema;
|
|
6
6
|
exports.oneOfSchema = oneOfSchema;
|
|
@@ -23,6 +23,10 @@ const DATE_INTERVAL_REGEX = /^\d{4}-\d{2}-\d{2}\/\d{4}-\d{2}-\d{2}$/;
|
|
|
23
23
|
exports.dateIntervalStringSchema = exports.stringSchema.regex(DATE_INTERVAL_REGEX).messages({
|
|
24
24
|
'string.pattern.base': `must be a DateInterval string`,
|
|
25
25
|
});
|
|
26
|
+
exports.DATE_TIME_STRING_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})?)?$/;
|
|
27
|
+
exports.dateTimeStringSchema = exports.stringSchema.regex(exports.DATE_TIME_STRING_REGEX).messages({
|
|
28
|
+
'string.pattern.base': `must be a DateTime string`,
|
|
29
|
+
});
|
|
26
30
|
/**
|
|
27
31
|
* Allows all values of a String Enum.
|
|
28
32
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
2
|
import {
|
|
3
3
|
_ms,
|
|
4
|
+
_since,
|
|
4
5
|
DeferredPromise,
|
|
5
6
|
localTime,
|
|
6
7
|
NumberOfMilliseconds,
|
|
@@ -75,7 +76,7 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
|
|
|
75
76
|
paused = pDefer()
|
|
76
77
|
if (debug) {
|
|
77
78
|
console.log(
|
|
78
|
-
`${localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${
|
|
79
|
+
`${localTime.now().toPretty()} transformThrottle activated: ${count} items passed in ${_since(start)}, will pause for ${_ms(interval * 1000 - (Date.now() - start))}`,
|
|
79
80
|
)
|
|
80
81
|
}
|
|
81
82
|
}
|
|
@@ -89,16 +90,23 @@ export function transformThrottle<T>(opt: TransformThrottleOptions): TransformTy
|
|
|
89
90
|
})
|
|
90
91
|
|
|
91
92
|
function onInterval(transform: Transform): void {
|
|
92
|
-
if (
|
|
93
|
+
if (paused) {
|
|
94
|
+
if (debug) {
|
|
95
|
+
console.log(`${localTime.now().toPretty()} transformThrottle resumed`)
|
|
96
|
+
}
|
|
93
97
|
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
paused.resolve()
|
|
99
|
+
paused = undefined
|
|
100
|
+
} else {
|
|
101
|
+
if (debug) {
|
|
102
|
+
console.log(
|
|
103
|
+
`${localTime.now().toPretty()} transformThrottle passed ${count} (of max ${throughput}) items in ${_since(start)}`,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
96
106
|
}
|
|
97
107
|
|
|
98
108
|
count = 0
|
|
99
109
|
start = Date.now()
|
|
100
110
|
timeout = setTimeout(() => onInterval(transform), interval * 1000)
|
|
101
|
-
paused.resolve()
|
|
102
|
-
paused = undefined
|
|
103
111
|
}
|
|
104
112
|
}
|
|
@@ -29,6 +29,13 @@ export const dateIntervalStringSchema = stringSchema.regex(DATE_INTERVAL_REGEX).
|
|
|
29
29
|
'string.pattern.base': `must be a DateInterval string`,
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
+
export const DATE_TIME_STRING_REGEX =
|
|
33
|
+
/^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})?)?$/
|
|
34
|
+
|
|
35
|
+
export const dateTimeStringSchema = stringSchema.regex(DATE_TIME_STRING_REGEX).messages({
|
|
36
|
+
'string.pattern.base': `must be a DateTime string`,
|
|
37
|
+
})
|
|
38
|
+
|
|
32
39
|
/**
|
|
33
40
|
* Allows all values of a String Enum.
|
|
34
41
|
*/
|