@naturalcycles/nodejs-lib 12.59.0 → 12.62.1
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/got/getGot.js +98 -28
- package/dist/got/got.model.d.ts +6 -0
- package/dist/index.d.ts +19 -19
- package/dist/index.js +19 -39
- package/dist/stream/ndjson/transformJsonParse.js +3 -3
- package/dist/stream/ndjson/transformToNDJson.js +2 -2
- package/dist/stream/sizeStack.d.ts +9 -0
- package/dist/stream/sizeStack.js +48 -0
- package/dist/stream/transform/transformBuffer.js +1 -1
- package/dist/stream/transform/transformFilter.d.ts +3 -4
- package/dist/stream/transform/transformFilter.js +5 -20
- package/dist/stream/transform/transformLogProgress.d.ts +20 -0
- package/dist/stream/transform/transformLogProgress.js +36 -18
- package/dist/stream/transform/transformMap.d.ts +2 -4
- package/dist/stream/transform/transformMap.js +6 -11
- package/dist/stream/transform/transformMapSimple.js +1 -1
- package/dist/stream/transform/transformMapSync.d.ts +5 -3
- package/dist/stream/transform/transformMapSync.js +28 -22
- package/dist/stream/transform/transformNoOp.js +1 -1
- package/dist/stream/transform/transformTap.js +3 -3
- package/dist/stream/transform/transformToArray.js +1 -1
- package/dist/stream/transform/transformToString.js +2 -2
- package/dist/stream/transform/worker/transformMultiThreaded.js +1 -1
- package/dist/stream/writable/writableFork.js +1 -1
- package/dist/stream/writable/writablePushToArray.js +1 -1
- package/dist/stream/writable/writableVoid.js +1 -1
- package/dist/util/zip.util.d.ts +15 -7
- package/dist/util/zip.util.js +27 -22
- package/package.json +2 -2
- package/src/got/getGot.ts +120 -31
- package/src/got/got.model.ts +8 -0
- package/src/index.ts +19 -38
- package/src/stream/ndjson/transformJsonParse.ts +3 -3
- package/src/stream/ndjson/transformToNDJson.ts +2 -2
- package/src/stream/sizeStack.ts +56 -0
- package/src/stream/transform/transformBuffer.ts +1 -1
- package/src/stream/transform/transformFilter.ts +6 -20
- package/src/stream/transform/transformLogProgress.ts +72 -23
- package/src/stream/transform/transformMap.ts +7 -14
- package/src/stream/transform/transformMapSimple.ts +1 -1
- package/src/stream/transform/transformMapSync.ts +40 -26
- package/src/stream/transform/transformNoOp.ts +1 -1
- package/src/stream/transform/transformTap.ts +3 -3
- package/src/stream/transform/transformToArray.ts +1 -1
- package/src/stream/transform/transformToString.ts +2 -2
- package/src/stream/transform/worker/transformMultiThreaded.ts +1 -1
- package/src/stream/writable/writableFork.ts +1 -1
- package/src/stream/writable/writablePushToArray.ts +1 -1
- package/src/stream/writable/writableVoid.ts +1 -1
- package/src/util/zip.util.ts +26 -20
package/dist/got/getGot.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.getGot = void 0;
|
|
|
4
4
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
5
|
const got_1 = require("got");
|
|
6
6
|
const __1 = require("..");
|
|
7
|
-
const colors_1 = require("../colors");
|
|
8
7
|
/**
|
|
9
8
|
* Returns instance of Got with "reasonable defaults":
|
|
10
9
|
*
|
|
@@ -14,12 +13,32 @@ const colors_1 = require("../colors");
|
|
|
14
13
|
*/
|
|
15
14
|
function getGot(opt = {}) {
|
|
16
15
|
opt.logger || (opt.logger = console);
|
|
16
|
+
if (opt.debug) {
|
|
17
|
+
opt.logStart = opt.logFinished = opt.logResponse = true;
|
|
18
|
+
}
|
|
17
19
|
return got_1.default.extend({
|
|
18
20
|
// Most-important is to set to anything non-empty (so, requests don't "hang" by default).
|
|
19
21
|
// Should be long enough to handle for slow responses from scaled cloud APIs in times of spikes
|
|
20
22
|
// Ideally should be LESS than default Request timeout in backend-lib (so, it has a chance to error
|
|
21
23
|
// before server times out with 503).
|
|
22
|
-
|
|
24
|
+
//
|
|
25
|
+
// UPD 2021-11-27
|
|
26
|
+
// There are 2 types/strategies for requests:
|
|
27
|
+
// 1. Optimized to get result no matter what. E.g in Cron jobs, where otherwise there'll be a job failure
|
|
28
|
+
// 2. Part of the Backend request, where we better retry quickly and fail on timeout before Backend aborts it with "503 Request timeout"
|
|
29
|
+
//
|
|
30
|
+
// Here it's hard to set the default timeout right for both use-cases.
|
|
31
|
+
// So, if it's important, you should override it according to your use-cases:
|
|
32
|
+
// - set it longer for Type 1 (e.g 120 seconds)
|
|
33
|
+
// - set it shorter for Type 2 (e.g 10/20 seconds)
|
|
34
|
+
// Please beware of default Retry strategy of Got:
|
|
35
|
+
// by default it will retry 2 times (after first try)
|
|
36
|
+
// First delay between tries will be ~1 second, then ~2 seconds
|
|
37
|
+
// Each retry it'll wait up to `timeout` (so, up to 60 seconds by default).
|
|
38
|
+
// So, for 3 tries it multiplies your timeout by 3 (+3 seconds between the tries).
|
|
39
|
+
// So, e.g 60 seconds timeout with 2 retries becomes up to 183 seconds.
|
|
40
|
+
// Which definitely doesn't fit into default "RequestTimeout"
|
|
41
|
+
timeout: 60000,
|
|
23
42
|
...opt,
|
|
24
43
|
hooks: {
|
|
25
44
|
...opt.hooks,
|
|
@@ -33,6 +52,11 @@ function getGot(opt = {}) {
|
|
|
33
52
|
// User hooks go AFTER
|
|
34
53
|
...(opt.hooks?.beforeRequest || []),
|
|
35
54
|
],
|
|
55
|
+
beforeRetry: [
|
|
56
|
+
gotBeforeRetryHook(opt),
|
|
57
|
+
// User hooks go AFTER
|
|
58
|
+
...(opt.hooks?.beforeRetry || []),
|
|
59
|
+
],
|
|
36
60
|
afterResponse: [
|
|
37
61
|
...(opt.hooks?.afterResponse || []),
|
|
38
62
|
// User hooks go BEFORE
|
|
@@ -69,20 +93,33 @@ exports.getGot = getGot;
|
|
|
69
93
|
function gotErrorHook(opt = {}) {
|
|
70
94
|
const { maxResponseLength = 10000 } = opt;
|
|
71
95
|
return err => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
96
|
+
const statusCode = err.response?.statusCode || 0;
|
|
97
|
+
const { method, url, prefixUrl } = err.options;
|
|
98
|
+
const shortUrl = getShortUrl(opt, url, prefixUrl);
|
|
99
|
+
const { started, retryCount } = (err.request?.options.context || {});
|
|
100
|
+
const body = err.response?.body
|
|
101
|
+
? (0, __1.inspectAny)(err.response.body, {
|
|
78
102
|
maxLen: maxResponseLength,
|
|
79
103
|
colors: false,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
})
|
|
105
|
+
: err.message;
|
|
106
|
+
// We don't include Response/Body/Message in the log, because it's included in the Error thrown from here
|
|
107
|
+
opt.logger.log([
|
|
108
|
+
' <<',
|
|
109
|
+
statusCode,
|
|
110
|
+
method,
|
|
111
|
+
shortUrl,
|
|
112
|
+
retryCount && `(retry ${retryCount})`,
|
|
113
|
+
'error',
|
|
114
|
+
started && 'in ' + (0, js_lib_1._since)(started),
|
|
115
|
+
]
|
|
116
|
+
.filter(Boolean)
|
|
117
|
+
.join(' '));
|
|
118
|
+
// timings are not part of err.message to allow automatic error grouping in Sentry
|
|
119
|
+
// Colors are not used, because there's high chance that this Error will be propagated all the way to the Frontend
|
|
120
|
+
err.message = [[statusCode, method, shortUrl].filter(Boolean).join(' '), body]
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.join('\n');
|
|
86
123
|
return err;
|
|
87
124
|
};
|
|
88
125
|
}
|
|
@@ -93,24 +130,64 @@ function gotBeforeRequestHook(opt) {
|
|
|
93
130
|
started: Date.now(),
|
|
94
131
|
};
|
|
95
132
|
if (opt.logStart) {
|
|
133
|
+
const { retryCount } = options.context;
|
|
96
134
|
const shortUrl = getShortUrl(opt, options.url, options.prefixUrl);
|
|
97
|
-
opt.logger.log([
|
|
135
|
+
opt.logger.log([' >>', options.method, shortUrl, retryCount && `(retry ${retryCount})`].join(' '));
|
|
98
136
|
}
|
|
99
137
|
};
|
|
100
138
|
}
|
|
139
|
+
// Here we log always, because it's similar to ErrorHook - we always log errors
|
|
140
|
+
// Because Retries are always result of some Error
|
|
141
|
+
function gotBeforeRetryHook(opt) {
|
|
142
|
+
const { maxResponseLength = 10000 } = opt;
|
|
143
|
+
return (options, err, retryCount) => {
|
|
144
|
+
// opt.logger!.log('beforeRetry', retryCount)
|
|
145
|
+
const statusCode = err?.response?.statusCode || 0;
|
|
146
|
+
const { method, url, prefixUrl } = options;
|
|
147
|
+
const shortUrl = getShortUrl(opt, url, prefixUrl);
|
|
148
|
+
const { started } = options.context;
|
|
149
|
+
Object.assign(options.context, { retryCount });
|
|
150
|
+
const body = err?.response?.body
|
|
151
|
+
? (0, __1.inspectAny)(err.response.body, {
|
|
152
|
+
maxLen: maxResponseLength,
|
|
153
|
+
colors: false,
|
|
154
|
+
})
|
|
155
|
+
: err?.message;
|
|
156
|
+
// We don't include Response/Body/Message in the log, because it's included in the Error thrown from here
|
|
157
|
+
opt.logger.warn([
|
|
158
|
+
[
|
|
159
|
+
' <<',
|
|
160
|
+
statusCode,
|
|
161
|
+
method,
|
|
162
|
+
shortUrl,
|
|
163
|
+
retryCount && retryCount > 1 ? `(retry ${retryCount - 1})` : '(first try)',
|
|
164
|
+
'error',
|
|
165
|
+
started && 'in ' + (0, js_lib_1._since)(started),
|
|
166
|
+
]
|
|
167
|
+
.filter(Boolean)
|
|
168
|
+
.join(' '),
|
|
169
|
+
body,
|
|
170
|
+
]
|
|
171
|
+
.filter(Boolean)
|
|
172
|
+
.join('\n'));
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// AfterResponseHook is never called on Error
|
|
176
|
+
// So, coloredHttpCode(resp.statusCode) is probably useless
|
|
101
177
|
function gotAfterResponseHook(opt = {}) {
|
|
102
178
|
return resp => {
|
|
103
179
|
const success = resp.statusCode >= 200 && resp.statusCode < 400;
|
|
104
180
|
if (opt.logFinished) {
|
|
105
|
-
const { started } = resp.request.options.context;
|
|
181
|
+
const { started, retryCount } = resp.request.options.context;
|
|
106
182
|
const { url, prefixUrl, method } = resp.request.options;
|
|
107
183
|
const shortUrl = getShortUrl(opt, url, prefixUrl);
|
|
108
184
|
opt.logger.log([
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
185
|
+
' <<',
|
|
186
|
+
resp.statusCode,
|
|
187
|
+
method,
|
|
188
|
+
shortUrl,
|
|
189
|
+
retryCount && `(retry ${retryCount - 1})`,
|
|
190
|
+
started && 'in ' + (0, js_lib_1._since)(started),
|
|
114
191
|
]
|
|
115
192
|
.filter(Boolean)
|
|
116
193
|
.join(' '));
|
|
@@ -123,13 +200,6 @@ function gotAfterResponseHook(opt = {}) {
|
|
|
123
200
|
return resp;
|
|
124
201
|
};
|
|
125
202
|
}
|
|
126
|
-
function coloredHttpCode(statusCode) {
|
|
127
|
-
if (statusCode < 400)
|
|
128
|
-
return (0, colors_1.dimGrey)(statusCode); // default
|
|
129
|
-
if (statusCode < 500)
|
|
130
|
-
return (0, colors_1.yellow)(statusCode);
|
|
131
|
-
return (0, colors_1.red)(statusCode);
|
|
132
|
-
}
|
|
133
203
|
function getShortUrl(opt, url, prefixUrl) {
|
|
134
204
|
let shortUrl = url.toString();
|
|
135
205
|
if (opt.logWithSearchParams === false) {
|
package/dist/got/got.model.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { AnyObject, CommonLogger } from '@naturalcycles/js-lib';
|
|
2
2
|
import type { Options } from 'got';
|
|
3
3
|
export interface GetGotOptions extends Options {
|
|
4
|
+
/**
|
|
5
|
+
* Set to `true` to enable all possible debug logging.
|
|
6
|
+
* Not safe in prod (as it logs Responses), but great to use during development.
|
|
7
|
+
*/
|
|
8
|
+
debug?: boolean;
|
|
4
9
|
/**
|
|
5
10
|
* @default false
|
|
6
11
|
*/
|
|
@@ -43,4 +48,5 @@ export interface GotRequestContext extends AnyObject {
|
|
|
43
48
|
* Millisecond-timestamp of when the request was started. To be able to count "time spent".
|
|
44
49
|
*/
|
|
45
50
|
started: number;
|
|
51
|
+
retryCount?: number;
|
|
46
52
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
import {
|
|
2
|
+
import { RequestError, TimeoutError } from 'got';
|
|
3
3
|
import type { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got } from 'got';
|
|
4
4
|
import { AnySchema, ValidationErrorItem } from 'joi';
|
|
5
5
|
import { _chunkBuffer } from './buffer/buffer.util';
|
|
@@ -11,14 +11,14 @@ import { Debug, IDebug, IDebugger } from './log/debug';
|
|
|
11
11
|
export * from './security/hash.util';
|
|
12
12
|
export * from './security/id.util';
|
|
13
13
|
export * from './security/secret.util';
|
|
14
|
-
|
|
14
|
+
export * from './colors/colors';
|
|
15
15
|
export * from './log/log.util';
|
|
16
16
|
import { slackDefaultMessagePrefixHook, SlackService } from './slack/slack.service';
|
|
17
17
|
import { SlackApiBody, SlackMessage, SlackMessagePrefixHook, SlackMessageProps, SlackServiceCfg } from './slack/slack.service.model';
|
|
18
18
|
import { NDJsonStats } from './stream/ndjson/ndjson.model';
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export * from './stream/ndjson/ndJsonFileRead';
|
|
20
|
+
export * from './stream/ndjson/ndJsonFileWrite';
|
|
21
|
+
export * from './stream/ndjson/ndjsonMap';
|
|
22
22
|
import { ndjsonStreamForEach, NDJSONStreamForEachOptions } from './stream/ndjson/ndjsonStreamForEach';
|
|
23
23
|
import { pipelineFromNDJsonFile, PipelineFromNDJsonFileOptions } from './stream/ndjson/pipelineFromNDJsonFile';
|
|
24
24
|
import { pipelineToNDJsonFile, PipelineToNDJsonFileOptions } from './stream/ndjson/pipelineToNDJsonFile';
|
|
@@ -26,25 +26,25 @@ import { streamToNDJsonFile } from './stream/ndjson/streamToNDJsonFile';
|
|
|
26
26
|
import { bufferReviver, transformJsonParse, TransformJsonParseOptions } from './stream/ndjson/transformJsonParse';
|
|
27
27
|
import { transformToNDJson, TransformToNDJsonOptions } from './stream/ndjson/transformToNDJson';
|
|
28
28
|
export * from './stream/pipeline/pipeline';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
export * from './stream/readable/readableCreate';
|
|
30
|
+
export * from './stream/readable/readableForEach';
|
|
31
|
+
export * from './stream/readable/readableFromArray';
|
|
32
|
+
export * from './stream/readable/readableMap';
|
|
33
|
+
export * from './stream/readable/readableMapToArray';
|
|
34
|
+
export * from './stream/readable/readableToArray';
|
|
35
35
|
import { ReadableTyped, TransformOptions, TransformTyped, WritableTyped } from './stream/stream.model';
|
|
36
36
|
export * from './stream/transform/transformBuffer';
|
|
37
37
|
export * from './stream/transform/transformFilter';
|
|
38
38
|
export * from './stream/transform/transformLimit';
|
|
39
39
|
export * from './stream/transform/transformLogProgress';
|
|
40
40
|
import { transformMap, TransformMapOptions } from './stream/transform/transformMap';
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
export * from './stream/transform/transformMapSimple';
|
|
42
|
+
export * from './stream/transform/transformNoOp';
|
|
43
43
|
import { transformMapSync, TransformMapSyncOptions } from './stream/transform/transformMapSync';
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
export * from './stream/transform/transformSplit';
|
|
45
|
+
export * from './stream/transform/transformTap';
|
|
46
|
+
export * from './stream/transform/transformToArray';
|
|
47
|
+
export * from './stream/transform/transformToString';
|
|
48
48
|
import { BaseWorkerClass, WorkerClassInterface } from './stream/transform/worker/baseWorkerClass';
|
|
49
49
|
import { transformMultiThreaded, TransformMultiThreadedOptions } from './stream/transform/worker/transformMultiThreaded';
|
|
50
50
|
import { WorkerInput, WorkerOutput } from './stream/transform/worker/transformMultiThreaded.model';
|
|
@@ -59,7 +59,7 @@ export * from './util/zip.util';
|
|
|
59
59
|
import { readAjvSchemas, readJsonSchemas } from './validation/ajv/ajv.util';
|
|
60
60
|
import { AjvSchema, AjvSchemaCfg, AjvValidationOptions } from './validation/ajv/ajvSchema';
|
|
61
61
|
import { AjvValidationError, AjvValidationErrorData } from './validation/ajv/ajvValidationError';
|
|
62
|
-
|
|
62
|
+
export * from './validation/ajv/getAjv';
|
|
63
63
|
import { ExtendedJoi, Joi } from './validation/joi/joi.extensions';
|
|
64
64
|
import { AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, SchemaTyped, StringSchemaTyped } from './validation/joi/joi.model';
|
|
65
65
|
export * from './validation/joi/joi.shared.schemas';
|
|
@@ -68,4 +68,4 @@ import { convert, getValidationResult, isValid, JoiValidationResult, undefinedIf
|
|
|
68
68
|
import { sanitizeHTML, SanitizeHTMLOptions } from './validation/sanitize.util';
|
|
69
69
|
import { runScript, RunScriptOptions } from './script';
|
|
70
70
|
export type { RunScriptOptions, JoiValidationErrorData, JoiValidationResult, ValidationErrorItem, ExtendedJoi, SchemaTyped, AnySchema, AnySchemaTyped, ArraySchemaTyped, BooleanSchemaTyped, NumberSchemaTyped, ObjectSchemaTyped, StringSchemaTyped, IDebug, IDebugger, SlackServiceCfg, SlackMessage, SlackMessageProps, SlackApiBody, SlackMessagePrefixHook, ReadableTyped, WritableTyped, TransformTyped, PipelineFromNDJsonFileOptions, PipelineToNDJsonFileOptions, TransformJsonParseOptions, TransformToNDJsonOptions, TransformMapOptions, TransformMapSyncOptions, NDJSONStreamForEachOptions, TransformOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData, SanitizeHTMLOptions, };
|
|
71
|
-
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, LRUMemoCache, Debug, SlackService, slackDefaultMessagePrefixHook,
|
|
71
|
+
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, LRUMemoCache, Debug, SlackService, slackDefaultMessagePrefixHook, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformMap, transformMapSync, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, inspectAnyStringifyFn, RequestError, TimeoutError, _chunkBuffer, Ajv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, sanitizeHTML, runScript, };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.runScript = exports.sanitizeHTML = exports.hasColors = exports.readAjvSchemas = exports.readJsonSchemas = void 0;
|
|
3
|
+
exports.runScript = exports.sanitizeHTML = exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.RequestError = exports.inspectAnyStringifyFn = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.transformMapSync = exports.transformMap = exports.transformToNDJson = exports.bufferReviver = exports.transformJsonParse = exports.streamToNDJsonFile = exports.NDJsonStats = exports.pipelineToNDJsonFile = exports.pipelineFromNDJsonFile = exports.ndjsonStreamForEach = exports.slackDefaultMessagePrefixHook = exports.SlackService = exports.Debug = exports.LRUMemoCache = exports.Joi = exports.convert = exports.undefinedIfInvalid = exports.isValid = exports.getValidationResult = exports.validate = exports.JoiValidationError = void 0;
|
|
5
4
|
const tslib_1 = require("tslib");
|
|
6
5
|
const ajv_1 = require("ajv");
|
|
7
6
|
exports.Ajv = ajv_1.default;
|
|
8
7
|
const got_1 = require("got");
|
|
9
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "RequestError", { enumerable: true, get: function () { return got_1.RequestError; } });
|
|
10
9
|
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return got_1.TimeoutError; } });
|
|
11
10
|
const buffer_util_1 = require("./buffer/buffer.util");
|
|
12
11
|
Object.defineProperty(exports, "_chunkBuffer", { enumerable: true, get: function () { return buffer_util_1._chunkBuffer; } });
|
|
@@ -19,20 +18,16 @@ Object.defineProperty(exports, "Debug", { enumerable: true, get: function () { r
|
|
|
19
18
|
(0, tslib_1.__exportStar)(require("./security/hash.util"), exports);
|
|
20
19
|
(0, tslib_1.__exportStar)(require("./security/id.util"), exports);
|
|
21
20
|
(0, tslib_1.__exportStar)(require("./security/secret.util"), exports);
|
|
22
|
-
|
|
23
|
-
Object.defineProperty(exports, "hasColors", { enumerable: true, get: function () { return colors_1.hasColors; } });
|
|
21
|
+
(0, tslib_1.__exportStar)(require("./colors/colors"), exports);
|
|
24
22
|
(0, tslib_1.__exportStar)(require("./log/log.util"), exports);
|
|
25
23
|
const slack_service_1 = require("./slack/slack.service");
|
|
26
24
|
Object.defineProperty(exports, "slackDefaultMessagePrefixHook", { enumerable: true, get: function () { return slack_service_1.slackDefaultMessagePrefixHook; } });
|
|
27
25
|
Object.defineProperty(exports, "SlackService", { enumerable: true, get: function () { return slack_service_1.SlackService; } });
|
|
28
26
|
const ndjson_model_1 = require("./stream/ndjson/ndjson.model");
|
|
29
27
|
Object.defineProperty(exports, "NDJsonStats", { enumerable: true, get: function () { return ndjson_model_1.NDJsonStats; } });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Object.defineProperty(exports, "ndJsonFileWrite", { enumerable: true, get: function () { return ndJsonFileWrite_1.ndJsonFileWrite; } });
|
|
34
|
-
const ndjsonMap_1 = require("./stream/ndjson/ndjsonMap");
|
|
35
|
-
Object.defineProperty(exports, "ndjsonMap", { enumerable: true, get: function () { return ndjsonMap_1.ndjsonMap; } });
|
|
28
|
+
(0, tslib_1.__exportStar)(require("./stream/ndjson/ndJsonFileRead"), exports);
|
|
29
|
+
(0, tslib_1.__exportStar)(require("./stream/ndjson/ndJsonFileWrite"), exports);
|
|
30
|
+
(0, tslib_1.__exportStar)(require("./stream/ndjson/ndjsonMap"), exports);
|
|
36
31
|
const ndjsonStreamForEach_1 = require("./stream/ndjson/ndjsonStreamForEach");
|
|
37
32
|
Object.defineProperty(exports, "ndjsonStreamForEach", { enumerable: true, get: function () { return ndjsonStreamForEach_1.ndjsonStreamForEach; } });
|
|
38
33
|
const pipelineFromNDJsonFile_1 = require("./stream/ndjson/pipelineFromNDJsonFile");
|
|
@@ -47,40 +42,26 @@ Object.defineProperty(exports, "transformJsonParse", { enumerable: true, get: fu
|
|
|
47
42
|
const transformToNDJson_1 = require("./stream/ndjson/transformToNDJson");
|
|
48
43
|
Object.defineProperty(exports, "transformToNDJson", { enumerable: true, get: function () { return transformToNDJson_1.transformToNDJson; } });
|
|
49
44
|
(0, tslib_1.__exportStar)(require("./stream/pipeline/pipeline"), exports);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const readableFromArray_1 = require("./stream/readable/readableFromArray");
|
|
57
|
-
Object.defineProperty(exports, "readableFromArray", { enumerable: true, get: function () { return readableFromArray_1.readableFromArray; } });
|
|
58
|
-
const readableMap_1 = require("./stream/readable/readableMap");
|
|
59
|
-
Object.defineProperty(exports, "readableMap", { enumerable: true, get: function () { return readableMap_1.readableMap; } });
|
|
60
|
-
const readableMapToArray_1 = require("./stream/readable/readableMapToArray");
|
|
61
|
-
Object.defineProperty(exports, "readableMapToArray", { enumerable: true, get: function () { return readableMapToArray_1.readableMapToArray; } });
|
|
62
|
-
const readableToArray_1 = require("./stream/readable/readableToArray");
|
|
63
|
-
Object.defineProperty(exports, "readableToArray", { enumerable: true, get: function () { return readableToArray_1.readableToArray; } });
|
|
45
|
+
(0, tslib_1.__exportStar)(require("./stream/readable/readableCreate"), exports);
|
|
46
|
+
(0, tslib_1.__exportStar)(require("./stream/readable/readableForEach"), exports);
|
|
47
|
+
(0, tslib_1.__exportStar)(require("./stream/readable/readableFromArray"), exports);
|
|
48
|
+
(0, tslib_1.__exportStar)(require("./stream/readable/readableMap"), exports);
|
|
49
|
+
(0, tslib_1.__exportStar)(require("./stream/readable/readableMapToArray"), exports);
|
|
50
|
+
(0, tslib_1.__exportStar)(require("./stream/readable/readableToArray"), exports);
|
|
64
51
|
(0, tslib_1.__exportStar)(require("./stream/transform/transformBuffer"), exports);
|
|
65
52
|
(0, tslib_1.__exportStar)(require("./stream/transform/transformFilter"), exports);
|
|
66
53
|
(0, tslib_1.__exportStar)(require("./stream/transform/transformLimit"), exports);
|
|
67
54
|
(0, tslib_1.__exportStar)(require("./stream/transform/transformLogProgress"), exports);
|
|
68
55
|
const transformMap_1 = require("./stream/transform/transformMap");
|
|
69
56
|
Object.defineProperty(exports, "transformMap", { enumerable: true, get: function () { return transformMap_1.transformMap; } });
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const transformNoOp_1 = require("./stream/transform/transformNoOp");
|
|
73
|
-
Object.defineProperty(exports, "transformNoOp", { enumerable: true, get: function () { return transformNoOp_1.transformNoOp; } });
|
|
57
|
+
(0, tslib_1.__exportStar)(require("./stream/transform/transformMapSimple"), exports);
|
|
58
|
+
(0, tslib_1.__exportStar)(require("./stream/transform/transformNoOp"), exports);
|
|
74
59
|
const transformMapSync_1 = require("./stream/transform/transformMapSync");
|
|
75
60
|
Object.defineProperty(exports, "transformMapSync", { enumerable: true, get: function () { return transformMapSync_1.transformMapSync; } });
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const transformToArray_1 = require("./stream/transform/transformToArray");
|
|
81
|
-
Object.defineProperty(exports, "transformToArray", { enumerable: true, get: function () { return transformToArray_1.transformToArray; } });
|
|
82
|
-
const transformToString_1 = require("./stream/transform/transformToString");
|
|
83
|
-
Object.defineProperty(exports, "transformToString", { enumerable: true, get: function () { return transformToString_1.transformToString; } });
|
|
61
|
+
(0, tslib_1.__exportStar)(require("./stream/transform/transformSplit"), exports);
|
|
62
|
+
(0, tslib_1.__exportStar)(require("./stream/transform/transformTap"), exports);
|
|
63
|
+
(0, tslib_1.__exportStar)(require("./stream/transform/transformToArray"), exports);
|
|
64
|
+
(0, tslib_1.__exportStar)(require("./stream/transform/transformToString"), exports);
|
|
84
65
|
const baseWorkerClass_1 = require("./stream/transform/worker/baseWorkerClass");
|
|
85
66
|
Object.defineProperty(exports, "BaseWorkerClass", { enumerable: true, get: function () { return baseWorkerClass_1.BaseWorkerClass; } });
|
|
86
67
|
const transformMultiThreaded_1 = require("./stream/transform/worker/transformMultiThreaded");
|
|
@@ -103,8 +84,7 @@ const ajvSchema_1 = require("./validation/ajv/ajvSchema");
|
|
|
103
84
|
Object.defineProperty(exports, "AjvSchema", { enumerable: true, get: function () { return ajvSchema_1.AjvSchema; } });
|
|
104
85
|
const ajvValidationError_1 = require("./validation/ajv/ajvValidationError");
|
|
105
86
|
Object.defineProperty(exports, "AjvValidationError", { enumerable: true, get: function () { return ajvValidationError_1.AjvValidationError; } });
|
|
106
|
-
|
|
107
|
-
Object.defineProperty(exports, "getAjv", { enumerable: true, get: function () { return getAjv_1.getAjv; } });
|
|
87
|
+
(0, tslib_1.__exportStar)(require("./validation/ajv/getAjv"), exports);
|
|
108
88
|
const joi_extensions_1 = require("./validation/joi/joi.extensions");
|
|
109
89
|
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return joi_extensions_1.Joi; } });
|
|
110
90
|
(0, tslib_1.__exportStar)(require("./validation/joi/joi.shared.schemas"), exports);
|
|
@@ -19,19 +19,19 @@ const stream_1 = require("stream");
|
|
|
19
19
|
function transformJsonParse(opt = {}) {
|
|
20
20
|
const { strict = true, reviver } = opt;
|
|
21
21
|
return new stream_1.Transform({
|
|
22
|
-
|
|
22
|
+
writableObjectMode: false,
|
|
23
23
|
readableObjectMode: true,
|
|
24
|
-
transform(chunk,
|
|
24
|
+
transform(chunk, _, cb) {
|
|
25
25
|
try {
|
|
26
26
|
const data = JSON.parse(chunk, reviver);
|
|
27
27
|
cb(null, data);
|
|
28
28
|
}
|
|
29
29
|
catch (err) {
|
|
30
|
-
// console.error(err)
|
|
31
30
|
if (strict) {
|
|
32
31
|
cb(err); // emit error
|
|
33
32
|
}
|
|
34
33
|
else {
|
|
34
|
+
console.error(err);
|
|
35
35
|
cb(); // emit no error, but no result neither
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -9,9 +9,9 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
9
9
|
function transformToNDJson(opt = {}) {
|
|
10
10
|
const { strict = true, separator = '\n', sortObjects = false, useFlatstr = false } = opt;
|
|
11
11
|
return new stream_1.Transform({
|
|
12
|
-
|
|
12
|
+
writableObjectMode: true,
|
|
13
13
|
readableObjectMode: false,
|
|
14
|
-
transform(chunk,
|
|
14
|
+
transform(chunk, _, cb) {
|
|
15
15
|
try {
|
|
16
16
|
if (sortObjects) {
|
|
17
17
|
chunk = (0, js_lib_1._sortObjectDeep)(chunk);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonLogger, NumberStack } from '@naturalcycles/js-lib';
|
|
2
|
+
export declare class SizeStack extends NumberStack {
|
|
3
|
+
name: string;
|
|
4
|
+
constructor(name: string, size: number);
|
|
5
|
+
total: number;
|
|
6
|
+
push(item: any): this;
|
|
7
|
+
getStats(): string;
|
|
8
|
+
static countItem(item: any, logger: CommonLogger, sizes?: SizeStack, sizesZipped?: SizeStack): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SizeStack = void 0;
|
|
4
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
|
+
const colors_1 = require("../colors");
|
|
6
|
+
const zip_util_1 = require("../util/zip.util");
|
|
7
|
+
class SizeStack extends js_lib_1.NumberStack {
|
|
8
|
+
constructor(name, size) {
|
|
9
|
+
super(size);
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.total = 0;
|
|
12
|
+
}
|
|
13
|
+
push(item) {
|
|
14
|
+
this.total += item;
|
|
15
|
+
return super.push(item);
|
|
16
|
+
}
|
|
17
|
+
getStats() {
|
|
18
|
+
// const pcs = this.percentiles([50, 90])
|
|
19
|
+
return [
|
|
20
|
+
' ' + this.name,
|
|
21
|
+
'avg',
|
|
22
|
+
(0, colors_1.yellow)((0, js_lib_1._hb)(this.avg())),
|
|
23
|
+
// 'p50',
|
|
24
|
+
// yellow(_hb(pcs[50])),
|
|
25
|
+
// 'p90',
|
|
26
|
+
// yellow(_hb(pcs[90])),
|
|
27
|
+
'total',
|
|
28
|
+
(0, colors_1.yellow)((0, js_lib_1._hb)(this.total)),
|
|
29
|
+
].join(' ');
|
|
30
|
+
}
|
|
31
|
+
static async countItem(item, logger, sizes, sizesZipped) {
|
|
32
|
+
if (!sizes)
|
|
33
|
+
return;
|
|
34
|
+
// try-catch, because we don't want to fail the pipeline on logProgress
|
|
35
|
+
try {
|
|
36
|
+
const buf = Buffer.from(JSON.stringify(item));
|
|
37
|
+
sizes.push(buf.byteLength);
|
|
38
|
+
if (sizesZipped) {
|
|
39
|
+
const { byteLength } = await (0, zip_util_1.gzipBuffer)(buf);
|
|
40
|
+
sizesZipped.push(byteLength);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
logger.warn(`transformLogProgress failed to JSON.stringify the chunk: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.SizeStack = SizeStack;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { AsyncPredicate, Predicate } from '@naturalcycles/js-lib';
|
|
2
2
|
import { TransformOptions, TransformTyped } from '../stream.model';
|
|
3
|
+
import { TransformMapOptions } from './transformMap';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
* So, it's recommended to use transformMap instead, that is both concurrent and has
|
|
6
|
-
* filtering feature by default.
|
|
5
|
+
* Just a convenience wrapper around `transformMap` that has built-in predicate filtering support.
|
|
7
6
|
*/
|
|
8
|
-
export declare function transformFilter<IN = any>(predicate: AsyncPredicate<IN>, opt?:
|
|
7
|
+
export declare function transformFilter<IN = any>(predicate: AsyncPredicate<IN>, opt?: TransformMapOptions): TransformTyped<IN, IN>;
|
|
9
8
|
/**
|
|
10
9
|
* Sync version of `transformFilter`
|
|
11
10
|
*/
|
|
@@ -2,29 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformFilterSync = exports.transformFilter = void 0;
|
|
4
4
|
const stream_1 = require("stream");
|
|
5
|
+
const transformMap_1 = require("./transformMap");
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
-
* So, it's recommended to use transformMap instead, that is both concurrent and has
|
|
8
|
-
* filtering feature by default.
|
|
7
|
+
* Just a convenience wrapper around `transformMap` that has built-in predicate filtering support.
|
|
9
8
|
*/
|
|
10
9
|
function transformFilter(predicate, opt = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
objectMode: true,
|
|
10
|
+
return (0, transformMap_1.transformMap)(v => v, {
|
|
11
|
+
predicate,
|
|
14
12
|
...opt,
|
|
15
|
-
async transform(chunk, _encoding, cb) {
|
|
16
|
-
try {
|
|
17
|
-
if (await predicate(chunk, index++)) {
|
|
18
|
-
cb(null, chunk); // pass through
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
cb(); // signal that we've finished processing, but emit no output here
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch (err) {
|
|
25
|
-
cb(err);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
13
|
});
|
|
29
14
|
}
|
|
30
15
|
exports.transformFilter = transformFilter;
|
|
@@ -36,7 +21,7 @@ function transformFilterSync(predicate, opt = {}) {
|
|
|
36
21
|
return new stream_1.Transform({
|
|
37
22
|
objectMode: true,
|
|
38
23
|
...opt,
|
|
39
|
-
|
|
24
|
+
transform(chunk, _, cb) {
|
|
40
25
|
try {
|
|
41
26
|
if (predicate(chunk, index++)) {
|
|
42
27
|
cb(null, chunk); // pass through
|
|
@@ -84,6 +84,26 @@ export interface TransformLogProgressOptions<IN = any> extends TransformOptions
|
|
|
84
84
|
* Defaults to 1.
|
|
85
85
|
*/
|
|
86
86
|
batchSize?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Experimental logging of item (shunk) sizes, when json-stringified.
|
|
89
|
+
*
|
|
90
|
+
* Defaults to false.
|
|
91
|
+
*
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
94
|
+
logSizes?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* How many last item sizes to keep in a buffer, to calculate stats (p50, p90, avg, etc).
|
|
97
|
+
* Defaults to 100_000.
|
|
98
|
+
* Cannot be Infinity.
|
|
99
|
+
*/
|
|
100
|
+
logSizesBuffer?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Works in addition to `logSizes`. Adds "zipped sizes".
|
|
103
|
+
*
|
|
104
|
+
* @experimental
|
|
105
|
+
*/
|
|
106
|
+
logZippedSizes?: boolean;
|
|
87
107
|
}
|
|
88
108
|
/**
|
|
89
109
|
* Pass-through transform that optionally logs progress.
|