@naturalcycles/nodejs-lib 12.52.0 → 12.53.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/got/getGot.js +4 -3
- package/dist/got/got.model.d.ts +5 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/stream/ndjson/transformToNDJson.d.ts +4 -0
- package/dist/stream/ndjson/transformToNDJson.js +15 -2
- package/dist/string/inspectAny.d.ts +5 -1
- package/dist/string/inspectAny.js +6 -1
- package/package.json +1 -1
- package/src/got/getGot.ts +6 -4
- package/src/got/got.model.ts +6 -1
- package/src/index.ts +2 -1
- package/src/stream/ndjson/transformToNDJson.ts +21 -2
- package/src/string/inspectAny.ts +6 -1
package/dist/got/getGot.js
CHANGED
|
@@ -13,6 +13,7 @@ const colors_1 = require("../colors");
|
|
|
13
13
|
* 3. Reasonable defaults(tm), e.g non-infinite Timeout
|
|
14
14
|
*/
|
|
15
15
|
function getGot(opt = {}) {
|
|
16
|
+
opt.logger || (opt.logger = console);
|
|
16
17
|
return got_1.default.extend({
|
|
17
18
|
// Most-important is to set to anything non-empty (so, requests don't "hang" by default).
|
|
18
19
|
// Should be long enough to handle for slow responses from scaled cloud APIs in times of spikes
|
|
@@ -93,7 +94,7 @@ function gotBeforeRequestHook(opt) {
|
|
|
93
94
|
};
|
|
94
95
|
if (opt.logStart) {
|
|
95
96
|
const shortUrl = getShortUrl(opt, options.url, options.prefixUrl);
|
|
96
|
-
|
|
97
|
+
opt.logger.log([(0, colors_1.dimGrey)(' >>'), (0, colors_1.dimGrey)(options.method), (0, colors_1.grey)(shortUrl)].join(' '));
|
|
97
98
|
}
|
|
98
99
|
};
|
|
99
100
|
}
|
|
@@ -104,7 +105,7 @@ function gotAfterResponseHook(opt = {}) {
|
|
|
104
105
|
const { started } = resp.request.options.context;
|
|
105
106
|
const { url, prefixUrl, method } = resp.request.options;
|
|
106
107
|
const shortUrl = getShortUrl(opt, url, prefixUrl);
|
|
107
|
-
|
|
108
|
+
opt.logger.log([
|
|
108
109
|
(0, colors_1.dimGrey)(' <<'),
|
|
109
110
|
coloredHttpCode(resp.statusCode),
|
|
110
111
|
(0, colors_1.dimGrey)(method),
|
|
@@ -117,7 +118,7 @@ function gotAfterResponseHook(opt = {}) {
|
|
|
117
118
|
}
|
|
118
119
|
// Error responses are not logged, cause they're included in Error message already
|
|
119
120
|
if (opt.logResponse && success) {
|
|
120
|
-
|
|
121
|
+
opt.logger.log((0, __1.inspectAny)(resp.body, { maxLen: opt.maxResponseLength }));
|
|
121
122
|
}
|
|
122
123
|
return resp;
|
|
123
124
|
};
|
package/dist/got/got.model.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject } from '@naturalcycles/js-lib';
|
|
1
|
+
import { AnyObject, CommonLogger } from '@naturalcycles/js-lib';
|
|
2
2
|
import type { Options } from 'got';
|
|
3
3
|
export interface GetGotOptions extends Options {
|
|
4
4
|
/**
|
|
@@ -27,6 +27,10 @@ export interface GetGotOptions extends Options {
|
|
|
27
27
|
* Set to false to strip searchParams from url when logging (both success and error)
|
|
28
28
|
*/
|
|
29
29
|
logWithSearchParams?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Defaults to `console`
|
|
32
|
+
*/
|
|
33
|
+
logger?: CommonLogger;
|
|
30
34
|
/**
|
|
31
35
|
* Max length of response object before it's truncated.
|
|
32
36
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ import { writableForEach } from './stream/writable/writableForEach';
|
|
|
51
51
|
import { writableFork } from './stream/writable/writableFork';
|
|
52
52
|
import { writablePushToArray } from './stream/writable/writablePushToArray';
|
|
53
53
|
import { writableVoid } from './stream/writable/writableVoid';
|
|
54
|
-
import { inspectAny, InspectAnyOptions } from './string/inspectAny';
|
|
54
|
+
import { inspectAny, InspectAnyOptions, inspectAnyStringifyFn } from './string/inspectAny';
|
|
55
55
|
import { requireEnvKeys, requireFileToExist } from './util/env.util';
|
|
56
56
|
import { LRUMemoCache } from './util/lruMemoCache';
|
|
57
57
|
import { gunzipBuffer, gunzipToString, gzipBuffer, gzipString, unzipBuffer, unzipToString, zipBuffer, zipString } from './util/zip.util';
|
|
@@ -66,4 +66,4 @@ import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi
|
|
|
66
66
|
import { convert, getValidationResult, isValid, JoiValidationResult, undefinedIfInvalid, validate } from './validation/joi/joi.validation.util';
|
|
67
67
|
import { sanitizeHTML, SanitizeHTMLOptions } from './validation/sanitize.util';
|
|
68
68
|
export type { 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, TransformLogProgressOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData, SanitizeHTMLOptions, };
|
|
69
|
-
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, booleanSchema, booleanDefaultToFalseSchema, stringSchema, numberSchema, integerSchema, percentageSchema, dateStringSchema, arraySchema, binarySchema, objectSchema, oneOfSchema, anySchema, anyObjectSchema, baseDBEntitySchema, savedDBEntitySchema, idSchema, unixTimestampSchema, verSchema, emailSchema, SEM_VER_PATTERN, semVerSchema, userAgentSchema, utcOffsetSchema, ipAddressSchema, slugSchema, urlSchema, processSharedUtil, zipBuffer, gzipBuffer, unzipBuffer, gunzipBuffer, zipString, gzipString, unzipToString, gunzipToString, requireEnvKeys, requireFileToExist, LRUMemoCache, stringId, stringIdAsync, stringIdUnsafe, ALPHABET_NUMBER, ALPHABET_LOWERCASE, ALPHABET_UPPERCASE, ALPHABET_ALPHANUMERIC_LOWERCASE, ALPHABET_ALPHANUMERIC_UPPERCASE, ALPHABET_ALPHANUMERIC, md5, hash, hashAsBuffer, md5AsBuffer, stringToBase64, base64ToString, bufferToBase64, base64ToBuffer, Debug, getSecretMap, setSecretMap, loadSecretsFromEnv, loadSecretsFromJsonFile, removeSecretsFromEnv, secret, secretOptional, memoryUsage, memoryUsageFull, SlackService, slackDefaultMessagePrefixHook, readableCreate, readableFrom, readableFromArray, readableToArray, readableForEach, readableForEachSync, readableMap, readableMapToArray, _pipeline, transformBuffer, ndjsonMap, ndJsonFileRead, ndJsonFileWrite, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformFilter, transformFilterSync, transformMap, transformMapSync, transformMapSimple, transformNoOp, writableForEach, writablePushToArray, transformSplit, transformToString, transformToArray, transformTap, transformLogProgress, transformLimit, writableVoid, writableFork, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, getGot, HTTPError, TimeoutError, _chunkBuffer, Ajv, getAjv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, hasColors, sanitizeHTML, };
|
|
69
|
+
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, booleanSchema, booleanDefaultToFalseSchema, stringSchema, numberSchema, integerSchema, percentageSchema, dateStringSchema, arraySchema, binarySchema, objectSchema, oneOfSchema, anySchema, anyObjectSchema, baseDBEntitySchema, savedDBEntitySchema, idSchema, unixTimestampSchema, verSchema, emailSchema, SEM_VER_PATTERN, semVerSchema, userAgentSchema, utcOffsetSchema, ipAddressSchema, slugSchema, urlSchema, processSharedUtil, zipBuffer, gzipBuffer, unzipBuffer, gunzipBuffer, zipString, gzipString, unzipToString, gunzipToString, requireEnvKeys, requireFileToExist, LRUMemoCache, stringId, stringIdAsync, stringIdUnsafe, ALPHABET_NUMBER, ALPHABET_LOWERCASE, ALPHABET_UPPERCASE, ALPHABET_ALPHANUMERIC_LOWERCASE, ALPHABET_ALPHANUMERIC_UPPERCASE, ALPHABET_ALPHANUMERIC, md5, hash, hashAsBuffer, md5AsBuffer, stringToBase64, base64ToString, bufferToBase64, base64ToBuffer, Debug, getSecretMap, setSecretMap, loadSecretsFromEnv, loadSecretsFromJsonFile, removeSecretsFromEnv, secret, secretOptional, memoryUsage, memoryUsageFull, SlackService, slackDefaultMessagePrefixHook, readableCreate, readableFrom, readableFromArray, readableToArray, readableForEach, readableForEachSync, readableMap, readableMapToArray, _pipeline, transformBuffer, ndjsonMap, ndJsonFileRead, ndJsonFileWrite, ndjsonStreamForEach, pipelineFromNDJsonFile, pipelineToNDJsonFile, NDJsonStats, streamToNDJsonFile, transformJsonParse, bufferReviver, transformToNDJson, transformFilter, transformFilterSync, transformMap, transformMapSync, transformMapSimple, transformNoOp, writableForEach, writablePushToArray, transformSplit, transformToString, transformToArray, transformTap, transformLogProgress, transformLimit, writableVoid, writableFork, transformMultiThreaded, BaseWorkerClass, tableDiff, inspectAny, inspectAnyStringifyFn, getGot, HTTPError, TimeoutError, _chunkBuffer, Ajv, getAjv, AjvSchema, AjvValidationError, readJsonSchemas, readAjvSchemas, hasColors, sanitizeHTML, };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ALPHABET_LOWERCASE = exports.ALPHABET_NUMBER = exports.stringIdUnsafe = exports.stringIdAsync = exports.stringId = exports.LRUMemoCache = exports.requireFileToExist = exports.requireEnvKeys = exports.gunzipToString = exports.unzipToString = exports.gzipString = exports.zipString = exports.gunzipBuffer = exports.unzipBuffer = exports.gzipBuffer = exports.zipBuffer = exports.processSharedUtil = exports.urlSchema = exports.slugSchema = exports.ipAddressSchema = exports.utcOffsetSchema = exports.userAgentSchema = exports.semVerSchema = exports.SEM_VER_PATTERN = exports.emailSchema = exports.verSchema = exports.unixTimestampSchema = exports.idSchema = exports.savedDBEntitySchema = exports.baseDBEntitySchema = exports.anyObjectSchema = exports.anySchema = exports.oneOfSchema = exports.objectSchema = exports.binarySchema = exports.arraySchema = exports.dateStringSchema = exports.percentageSchema = exports.integerSchema = exports.numberSchema = exports.stringSchema = exports.booleanDefaultToFalseSchema = exports.booleanSchema = exports.Joi = exports.convert = exports.undefinedIfInvalid = exports.isValid = exports.getValidationResult = exports.validate = exports.JoiValidationError = void 0;
|
|
4
4
|
exports.transformMapSimple = exports.transformMapSync = exports.transformMap = exports.transformFilterSync = exports.transformFilter = exports.transformToNDJson = exports.bufferReviver = exports.transformJsonParse = exports.streamToNDJsonFile = exports.NDJsonStats = exports.pipelineToNDJsonFile = exports.pipelineFromNDJsonFile = exports.ndjsonStreamForEach = exports.ndJsonFileWrite = exports.ndJsonFileRead = exports.ndjsonMap = exports.transformBuffer = exports._pipeline = exports.readableMapToArray = exports.readableMap = exports.readableForEachSync = exports.readableForEach = exports.readableToArray = exports.readableFromArray = exports.readableFrom = exports.readableCreate = exports.slackDefaultMessagePrefixHook = exports.SlackService = exports.memoryUsageFull = exports.memoryUsage = exports.secretOptional = exports.secret = exports.removeSecretsFromEnv = exports.loadSecretsFromJsonFile = exports.loadSecretsFromEnv = exports.setSecretMap = exports.getSecretMap = exports.Debug = exports.base64ToBuffer = exports.bufferToBase64 = exports.base64ToString = exports.stringToBase64 = exports.md5AsBuffer = exports.hashAsBuffer = exports.hash = exports.md5 = exports.ALPHABET_ALPHANUMERIC = exports.ALPHABET_ALPHANUMERIC_UPPERCASE = exports.ALPHABET_ALPHANUMERIC_LOWERCASE = exports.ALPHABET_UPPERCASE = void 0;
|
|
5
|
-
exports.sanitizeHTML = exports.hasColors = exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.getAjv = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.HTTPError = exports.getGot = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.writableFork = exports.writableVoid = exports.transformLimit = exports.transformLogProgress = exports.transformTap = exports.transformToArray = exports.transformToString = exports.transformSplit = exports.writablePushToArray = exports.writableForEach = exports.transformNoOp = void 0;
|
|
5
|
+
exports.sanitizeHTML = exports.hasColors = exports.readAjvSchemas = exports.readJsonSchemas = exports.AjvValidationError = exports.AjvSchema = exports.getAjv = exports.Ajv = exports._chunkBuffer = exports.TimeoutError = exports.HTTPError = exports.getGot = exports.inspectAnyStringifyFn = exports.inspectAny = exports.tableDiff = exports.BaseWorkerClass = exports.transformMultiThreaded = exports.writableFork = exports.writableVoid = exports.transformLimit = exports.transformLogProgress = exports.transformTap = exports.transformToArray = exports.transformToString = exports.transformSplit = exports.writablePushToArray = exports.writableForEach = exports.transformNoOp = void 0;
|
|
6
6
|
const ajv_1 = require("ajv");
|
|
7
7
|
exports.Ajv = ajv_1.default;
|
|
8
8
|
const got_1 = require("got");
|
|
@@ -128,6 +128,7 @@ const writableVoid_1 = require("./stream/writable/writableVoid");
|
|
|
128
128
|
Object.defineProperty(exports, "writableVoid", { enumerable: true, get: function () { return writableVoid_1.writableVoid; } });
|
|
129
129
|
const inspectAny_1 = require("./string/inspectAny");
|
|
130
130
|
Object.defineProperty(exports, "inspectAny", { enumerable: true, get: function () { return inspectAny_1.inspectAny; } });
|
|
131
|
+
Object.defineProperty(exports, "inspectAnyStringifyFn", { enumerable: true, get: function () { return inspectAny_1.inspectAnyStringifyFn; } });
|
|
131
132
|
const env_util_1 = require("./util/env.util");
|
|
132
133
|
Object.defineProperty(exports, "requireEnvKeys", { enumerable: true, get: function () { return env_util_1.requireEnvKeys; } });
|
|
133
134
|
Object.defineProperty(exports, "requireFileToExist", { enumerable: true, get: function () { return env_util_1.requireFileToExist; } });
|
|
@@ -16,6 +16,10 @@ export interface TransformToNDJsonOptions {
|
|
|
16
16
|
* @default `\n`
|
|
17
17
|
*/
|
|
18
18
|
separator?: string;
|
|
19
|
+
/**
|
|
20
|
+
* @experimental
|
|
21
|
+
*/
|
|
22
|
+
useFlatstr?: boolean;
|
|
19
23
|
}
|
|
20
24
|
/**
|
|
21
25
|
* Transforms objects (objectMode=true) into chunks \n-terminated JSON strings (readableObjectMode=false).
|
|
@@ -7,7 +7,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
7
7
|
* Transforms objects (objectMode=true) into chunks \n-terminated JSON strings (readableObjectMode=false).
|
|
8
8
|
*/
|
|
9
9
|
function transformToNDJson(opt = {}) {
|
|
10
|
-
const { strict = true, separator = '\n', sortObjects = false } = opt;
|
|
10
|
+
const { strict = true, separator = '\n', sortObjects = false, useFlatstr = false } = opt;
|
|
11
11
|
return new stream_1.Transform({
|
|
12
12
|
objectMode: true,
|
|
13
13
|
readableObjectMode: false,
|
|
@@ -16,7 +16,12 @@ function transformToNDJson(opt = {}) {
|
|
|
16
16
|
if (sortObjects) {
|
|
17
17
|
chunk = (0, js_lib_1._sortObjectDeep)(chunk);
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
if (useFlatstr) {
|
|
20
|
+
cb(null, flatstr(JSON.stringify(chunk) + separator));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
cb(null, JSON.stringify(chunk) + separator);
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
catch (err) {
|
|
22
27
|
console.error(err);
|
|
@@ -31,3 +36,11 @@ function transformToNDJson(opt = {}) {
|
|
|
31
36
|
});
|
|
32
37
|
}
|
|
33
38
|
exports.transformToNDJson = transformToNDJson;
|
|
39
|
+
/**
|
|
40
|
+
* Based on: https://github.com/davidmarkclements/flatstr/blob/master/index.js
|
|
41
|
+
*/
|
|
42
|
+
function flatstr(s) {
|
|
43
|
+
// eslint-disable-next-line
|
|
44
|
+
s | 0;
|
|
45
|
+
return s;
|
|
46
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { InspectOptions } from 'util';
|
|
3
|
-
import { StringifyAnyOptions } from '@naturalcycles/js-lib';
|
|
3
|
+
import { StringifyAnyOptions, JsonStringifyFunction } from '@naturalcycles/js-lib';
|
|
4
4
|
export interface InspectAnyOptions extends StringifyAnyOptions, InspectOptions {
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
|
|
8
|
+
*/
|
|
9
|
+
export declare const inspectAnyStringifyFn: JsonStringifyFunction;
|
|
6
10
|
/**
|
|
7
11
|
* Transforms ANY to human-readable string (via util.inspect mainly).
|
|
8
12
|
* Safe (no error throwing).
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.inspectAny = void 0;
|
|
3
|
+
exports.inspectAny = exports.inspectAnyStringifyFn = void 0;
|
|
4
4
|
const util_1 = require("util");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const INSPECT_OPT = {
|
|
7
7
|
breakLength: 80,
|
|
8
8
|
depth: 10, // default: 2
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
|
|
12
|
+
*/
|
|
13
|
+
const inspectAnyStringifyFn = obj => inspectAny(obj);
|
|
14
|
+
exports.inspectAnyStringifyFn = inspectAnyStringifyFn;
|
|
10
15
|
/**
|
|
11
16
|
* Transforms ANY to human-readable string (via util.inspect mainly).
|
|
12
17
|
* Safe (no error throwing).
|
package/package.json
CHANGED
package/src/got/getGot.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { URL } from 'url'
|
|
2
|
-
import {
|
|
2
|
+
import { _since } from '@naturalcycles/js-lib'
|
|
3
3
|
import got, { AfterResponseHook, BeforeErrorHook, BeforeRequestHook, Got, HTTPError } from 'got'
|
|
4
4
|
import { inspectAny } from '..'
|
|
5
5
|
import { dimGrey, grey, red, yellow } from '../colors'
|
|
@@ -13,6 +13,8 @@ import { GetGotOptions, GotRequestContext } from './got.model'
|
|
|
13
13
|
* 3. Reasonable defaults(tm), e.g non-infinite Timeout
|
|
14
14
|
*/
|
|
15
15
|
export function getGot(opt: GetGotOptions = {}): Got {
|
|
16
|
+
opt.logger ||= console
|
|
17
|
+
|
|
16
18
|
return got.extend({
|
|
17
19
|
// Most-important is to set to anything non-empty (so, requests don't "hang" by default).
|
|
18
20
|
// Should be long enough to handle for slow responses from scaled cloud APIs in times of spikes
|
|
@@ -99,7 +101,7 @@ function gotBeforeRequestHook(opt: GetGotOptions): BeforeRequestHook {
|
|
|
99
101
|
|
|
100
102
|
if (opt.logStart) {
|
|
101
103
|
const shortUrl = getShortUrl(opt, options.url, options.prefixUrl)
|
|
102
|
-
|
|
104
|
+
opt.logger!.log([dimGrey(' >>'), dimGrey(options.method), grey(shortUrl)].join(' '))
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
}
|
|
@@ -113,7 +115,7 @@ function gotAfterResponseHook(opt: GetGotOptions = {}): AfterResponseHook {
|
|
|
113
115
|
const { url, prefixUrl, method } = resp.request.options
|
|
114
116
|
const shortUrl = getShortUrl(opt, url, prefixUrl)
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
opt.logger!.log(
|
|
117
119
|
[
|
|
118
120
|
dimGrey(' <<'),
|
|
119
121
|
coloredHttpCode(resp.statusCode),
|
|
@@ -129,7 +131,7 @@ function gotAfterResponseHook(opt: GetGotOptions = {}): AfterResponseHook {
|
|
|
129
131
|
|
|
130
132
|
// Error responses are not logged, cause they're included in Error message already
|
|
131
133
|
if (opt.logResponse && success) {
|
|
132
|
-
|
|
134
|
+
opt.logger!.log(inspectAny(resp.body, { maxLen: opt.maxResponseLength }))
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
return resp
|
package/src/got/got.model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyObject } from '@naturalcycles/js-lib'
|
|
1
|
+
import { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
|
|
2
2
|
import type { Options } from 'got'
|
|
3
3
|
|
|
4
4
|
export interface GetGotOptions extends Options {
|
|
@@ -33,6 +33,11 @@ export interface GetGotOptions extends Options {
|
|
|
33
33
|
*/
|
|
34
34
|
logWithSearchParams?: boolean
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Defaults to `console`
|
|
38
|
+
*/
|
|
39
|
+
logger?: CommonLogger
|
|
40
|
+
|
|
36
41
|
/**
|
|
37
42
|
* Max length of response object before it's truncated.
|
|
38
43
|
*
|
package/src/index.ts
CHANGED
|
@@ -108,7 +108,7 @@ import { writableForEach } from './stream/writable/writableForEach'
|
|
|
108
108
|
import { writableFork } from './stream/writable/writableFork'
|
|
109
109
|
import { writablePushToArray } from './stream/writable/writablePushToArray'
|
|
110
110
|
import { writableVoid } from './stream/writable/writableVoid'
|
|
111
|
-
import { inspectAny, InspectAnyOptions } from './string/inspectAny'
|
|
111
|
+
import { inspectAny, InspectAnyOptions, inspectAnyStringifyFn } from './string/inspectAny'
|
|
112
112
|
import { requireEnvKeys, requireFileToExist } from './util/env.util'
|
|
113
113
|
import { LRUMemoCache } from './util/lruMemoCache'
|
|
114
114
|
import {
|
|
@@ -339,6 +339,7 @@ export {
|
|
|
339
339
|
BaseWorkerClass,
|
|
340
340
|
tableDiff,
|
|
341
341
|
inspectAny,
|
|
342
|
+
inspectAnyStringifyFn,
|
|
342
343
|
getGot,
|
|
343
344
|
HTTPError,
|
|
344
345
|
TimeoutError,
|
|
@@ -21,6 +21,11 @@ export interface TransformToNDJsonOptions {
|
|
|
21
21
|
* @default `\n`
|
|
22
22
|
*/
|
|
23
23
|
separator?: string
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @experimental
|
|
27
|
+
*/
|
|
28
|
+
useFlatstr?: boolean
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
/**
|
|
@@ -29,7 +34,7 @@ export interface TransformToNDJsonOptions {
|
|
|
29
34
|
export function transformToNDJson<IN = any>(
|
|
30
35
|
opt: TransformToNDJsonOptions = {},
|
|
31
36
|
): TransformTyped<IN, string> {
|
|
32
|
-
const { strict = true, separator = '\n', sortObjects = false } = opt
|
|
37
|
+
const { strict = true, separator = '\n', sortObjects = false, useFlatstr = false } = opt
|
|
33
38
|
|
|
34
39
|
return new Transform({
|
|
35
40
|
objectMode: true,
|
|
@@ -39,7 +44,12 @@ export function transformToNDJson<IN = any>(
|
|
|
39
44
|
if (sortObjects) {
|
|
40
45
|
chunk = _sortObjectDeep(chunk as any)
|
|
41
46
|
}
|
|
42
|
-
|
|
47
|
+
|
|
48
|
+
if (useFlatstr) {
|
|
49
|
+
cb(null, flatstr(JSON.stringify(chunk) + separator))
|
|
50
|
+
} else {
|
|
51
|
+
cb(null, JSON.stringify(chunk) + separator)
|
|
52
|
+
}
|
|
43
53
|
} catch (err) {
|
|
44
54
|
console.error(err)
|
|
45
55
|
|
|
@@ -52,3 +62,12 @@ export function transformToNDJson<IN = any>(
|
|
|
52
62
|
},
|
|
53
63
|
})
|
|
54
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Based on: https://github.com/davidmarkclements/flatstr/blob/master/index.js
|
|
68
|
+
*/
|
|
69
|
+
function flatstr(s: any): string {
|
|
70
|
+
// eslint-disable-next-line
|
|
71
|
+
s | 0
|
|
72
|
+
return s
|
|
73
|
+
}
|
package/src/string/inspectAny.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inspect, InspectOptions } from 'util'
|
|
2
|
-
import { StringifyAnyOptions, _stringifyAny } from '@naturalcycles/js-lib'
|
|
2
|
+
import { StringifyAnyOptions, _stringifyAny, JsonStringifyFunction } from '@naturalcycles/js-lib'
|
|
3
3
|
|
|
4
4
|
export interface InspectAnyOptions extends StringifyAnyOptions, InspectOptions {}
|
|
5
5
|
|
|
@@ -8,6 +8,11 @@ const INSPECT_OPT: InspectOptions = {
|
|
|
8
8
|
depth: 10, // default: 2
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Just a convenience export of a const that fulfills the JsonStringifyFunction interface.
|
|
13
|
+
*/
|
|
14
|
+
export const inspectAnyStringifyFn: JsonStringifyFunction = obj => inspectAny(obj)
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* Transforms ANY to human-readable string (via util.inspect mainly).
|
|
13
18
|
* Safe (no error throwing).
|