@naturalcycles/nodejs-lib 12.65.0 → 12.65.3
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 +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/util/lruMemoCache.d.ts +4 -3
- package/dist/util/lruMemoCache.js +5 -2
- package/dist/validation/ajv/ajv.util.js +1 -1
- package/dist/validation/ajv/ajvSchema.js +1 -1
- package/package.json +3 -3
- package/src/got/getGot.ts +9 -0
- package/src/index.ts +1 -2
- package/src/util/lruMemoCache.ts +10 -6
- package/src/validation/ajv/ajv.util.ts +1 -1
- package/src/validation/ajv/ajvSchema.ts +1 -1
package/dist/got/getGot.js
CHANGED
|
@@ -178,6 +178,11 @@ function gotBeforeRetryHook(opt) {
|
|
|
178
178
|
return (options, err, retryCount) => {
|
|
179
179
|
// opt.logger!.log('beforeRetry', retryCount)
|
|
180
180
|
const statusCode = err?.response?.statusCode || 0;
|
|
181
|
+
if (statusCode && statusCode < 300) {
|
|
182
|
+
// todo: possibly remove the log message completely in the future
|
|
183
|
+
opt.logger.log(`skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
181
186
|
const { method, url, prefixUrl } = options;
|
|
182
187
|
const shortUrl = getShortUrl(opt, url, prefixUrl);
|
|
183
188
|
const { started } = options.context;
|
package/dist/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export * from './stream/writable/writablePushToArray';
|
|
|
54
54
|
export * from './stream/writable/writableVoid';
|
|
55
55
|
import { inspectAny, InspectAnyOptions, inspectAnyStringifyFn } from './string/inspectAny';
|
|
56
56
|
export * from './util/env.util';
|
|
57
|
-
|
|
57
|
+
export * from './util/lruMemoCache';
|
|
58
58
|
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';
|
|
@@ -67,4 +67,4 @@ import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi
|
|
|
67
67
|
import { convert, getValidationResult, isValid, JoiValidationResult, undefinedIfInvalid, validate } from './validation/joi/joi.validation.util';
|
|
68
68
|
import { runScript, RunScriptOptions } from './script';
|
|
69
69
|
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, };
|
|
70
|
-
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi,
|
|
70
|
+
export { JoiValidationError, validate, getValidationResult, isValid, undefinedIfInvalid, convert, Joi, 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, runScript, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runScript = 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.
|
|
3
|
+
exports.runScript = 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.Joi = exports.convert = exports.undefinedIfInvalid = exports.isValid = exports.getValidationResult = exports.validate = exports.JoiValidationError = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ajv_1 = require("ajv");
|
|
6
6
|
exports.Ajv = ajv_1.default;
|
|
@@ -74,8 +74,7 @@ const inspectAny_1 = require("./string/inspectAny");
|
|
|
74
74
|
Object.defineProperty(exports, "inspectAny", { enumerable: true, get: function () { return inspectAny_1.inspectAny; } });
|
|
75
75
|
Object.defineProperty(exports, "inspectAnyStringifyFn", { enumerable: true, get: function () { return inspectAny_1.inspectAnyStringifyFn; } });
|
|
76
76
|
(0, tslib_1.__exportStar)(require("./util/env.util"), exports);
|
|
77
|
-
|
|
78
|
-
Object.defineProperty(exports, "LRUMemoCache", { enumerable: true, get: function () { return lruMemoCache_1.LRUMemoCache; } });
|
|
77
|
+
(0, tslib_1.__exportStar)(require("./util/lruMemoCache"), exports);
|
|
79
78
|
(0, tslib_1.__exportStar)(require("./util/zip.util"), exports);
|
|
80
79
|
const ajv_util_1 = require("./validation/ajv/ajv.util");
|
|
81
80
|
Object.defineProperty(exports, "readAjvSchemas", { enumerable: true, get: function () { return ajv_util_1.readAjvSchemas; } });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MemoCache } from '@naturalcycles/js-lib';
|
|
2
2
|
import LRUCache = require('lru-cache');
|
|
3
|
-
export
|
|
3
|
+
export interface LRUMemoCacheOptions<KEY, VALUE> extends Partial<LRUCache.Options<KEY, VALUE>> {
|
|
4
|
+
}
|
|
4
5
|
/**
|
|
5
6
|
* @example
|
|
6
7
|
* Use it like this:
|
|
@@ -8,8 +9,8 @@ export declare type LRUMemoCacheOpts = LRUCache.Options<string, any>;
|
|
|
8
9
|
* @_Memo({ cacheFactory: () => new LRUMemoCache({...}) })
|
|
9
10
|
* method1 ()
|
|
10
11
|
*/
|
|
11
|
-
export declare class LRUMemoCache implements MemoCache {
|
|
12
|
-
constructor(opt:
|
|
12
|
+
export declare class LRUMemoCache<KEY = any, VALUE = any> implements MemoCache<KEY, VALUE> {
|
|
13
|
+
constructor(opt: LRUMemoCacheOptions<KEY, VALUE>);
|
|
13
14
|
private lru;
|
|
14
15
|
has(k: any): boolean;
|
|
15
16
|
get(k: any): any;
|
|
@@ -11,7 +11,10 @@ const LRUCache = require("lru-cache");
|
|
|
11
11
|
*/
|
|
12
12
|
class LRUMemoCache {
|
|
13
13
|
constructor(opt) {
|
|
14
|
-
this.lru = new LRUCache(
|
|
14
|
+
this.lru = new LRUCache({
|
|
15
|
+
max: 100,
|
|
16
|
+
...opt,
|
|
17
|
+
});
|
|
15
18
|
}
|
|
16
19
|
has(k) {
|
|
17
20
|
return this.lru.has(k);
|
|
@@ -23,7 +26,7 @@ class LRUMemoCache {
|
|
|
23
26
|
this.lru.set(k, v);
|
|
24
27
|
}
|
|
25
28
|
clear() {
|
|
26
|
-
this.lru.
|
|
29
|
+
this.lru.clear();
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
exports.LRUMemoCache = LRUMemoCache;
|
|
@@ -13,7 +13,7 @@ const ajvSchema_1 = require("./ajvSchema");
|
|
|
13
13
|
* @experimental
|
|
14
14
|
*/
|
|
15
15
|
function readJsonSchemas(patterns, opt) {
|
|
16
|
-
return globby.sync(patterns, opt).map(fileName => JSON.parse(fs.readFileSync(fileName, '
|
|
16
|
+
return globby.sync(patterns, opt).map(fileName => JSON.parse(fs.readFileSync(fileName, 'utf8')));
|
|
17
17
|
}
|
|
18
18
|
exports.readJsonSchemas = readJsonSchemas;
|
|
19
19
|
/**
|
|
@@ -60,7 +60,7 @@ class AjvSchema {
|
|
|
60
60
|
*/
|
|
61
61
|
static readJsonSync(filePath, cfg = {}) {
|
|
62
62
|
(0, index_1.requireFileToExist)(filePath);
|
|
63
|
-
const schema = JSON.parse(fs.readFileSync(filePath, '
|
|
63
|
+
const schema = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
64
64
|
return new AjvSchema(schema, cfg);
|
|
65
65
|
}
|
|
66
66
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
|
-
"version": "12.65.
|
|
3
|
+
"version": "12.65.3",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"docs-serve": "vuepress dev docs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@naturalcycles/js-lib": "^14.0.0",
|
|
18
18
|
"@naturalcycles/time-lib": "^3.0.1",
|
|
19
|
-
"@types/lru-cache": "^
|
|
19
|
+
"@types/lru-cache": "^7.4.0",
|
|
20
20
|
"@types/through2-concurrent": "^2.0.0",
|
|
21
21
|
"ajv": "^8.6.2",
|
|
22
22
|
"ajv-formats": "^2.1.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"globby": "^11.0.0",
|
|
33
33
|
"got": "^11.0.1",
|
|
34
34
|
"joi": "17.4.2",
|
|
35
|
-
"lru-cache": "^
|
|
35
|
+
"lru-cache": "^7.4.0",
|
|
36
36
|
"move-file": "^2.0.0",
|
|
37
37
|
"nanoid": "^3.0.0",
|
|
38
38
|
"through2-concurrent": "^2.0.0",
|
package/src/got/getGot.ts
CHANGED
|
@@ -204,6 +204,15 @@ function gotBeforeRetryHook(opt: GetGotOptions): BeforeRetryHook {
|
|
|
204
204
|
return (options, err, retryCount) => {
|
|
205
205
|
// opt.logger!.log('beforeRetry', retryCount)
|
|
206
206
|
const statusCode = err?.response?.statusCode || 0
|
|
207
|
+
|
|
208
|
+
if (statusCode && statusCode < 300) {
|
|
209
|
+
// todo: possibly remove the log message completely in the future
|
|
210
|
+
opt.logger!.log(
|
|
211
|
+
`skipping got.beforeRetry hook as statusCode is ${statusCode}, err.msg is ${err?.message}`,
|
|
212
|
+
)
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
|
|
207
216
|
const { method, url, prefixUrl } = options
|
|
208
217
|
const shortUrl = getShortUrl(opt, url, prefixUrl)
|
|
209
218
|
const { started } = options.context as GotRequestContext
|
package/src/index.ts
CHANGED
|
@@ -81,7 +81,7 @@ export * from './stream/writable/writablePushToArray'
|
|
|
81
81
|
export * from './stream/writable/writableVoid'
|
|
82
82
|
import { inspectAny, InspectAnyOptions, inspectAnyStringifyFn } from './string/inspectAny'
|
|
83
83
|
export * from './util/env.util'
|
|
84
|
-
|
|
84
|
+
export * from './util/lruMemoCache'
|
|
85
85
|
export * from './util/zip.util'
|
|
86
86
|
import { readAjvSchemas, readJsonSchemas } from './validation/ajv/ajv.util'
|
|
87
87
|
import { AjvSchema, AjvSchemaCfg, AjvValidationOptions } from './validation/ajv/ajvSchema'
|
|
@@ -165,7 +165,6 @@ export {
|
|
|
165
165
|
undefinedIfInvalid,
|
|
166
166
|
convert,
|
|
167
167
|
Joi,
|
|
168
|
-
LRUMemoCache,
|
|
169
168
|
Debug,
|
|
170
169
|
SlackService,
|
|
171
170
|
slackDefaultMessagePrefixHook,
|
package/src/util/lruMemoCache.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { MemoCache } from '@naturalcycles/js-lib'
|
|
2
2
|
import LRUCache = require('lru-cache')
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Partial, to be able to provide default `max`
|
|
5
|
+
export interface LRUMemoCacheOptions<KEY, VALUE> extends Partial<LRUCache.Options<KEY, VALUE>> {}
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @example
|
|
@@ -10,12 +11,15 @@ export type LRUMemoCacheOpts = LRUCache.Options<string, any>
|
|
|
10
11
|
* @_Memo({ cacheFactory: () => new LRUMemoCache({...}) })
|
|
11
12
|
* method1 ()
|
|
12
13
|
*/
|
|
13
|
-
export class LRUMemoCache implements MemoCache {
|
|
14
|
-
constructor(opt:
|
|
15
|
-
this.lru = new LRUCache<
|
|
14
|
+
export class LRUMemoCache<KEY = any, VALUE = any> implements MemoCache<KEY, VALUE> {
|
|
15
|
+
constructor(opt: LRUMemoCacheOptions<KEY, VALUE>) {
|
|
16
|
+
this.lru = new LRUCache<KEY, VALUE>({
|
|
17
|
+
max: 100,
|
|
18
|
+
...opt,
|
|
19
|
+
})
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
private lru!: LRUCache<
|
|
22
|
+
private lru!: LRUCache<KEY, VALUE>
|
|
19
23
|
|
|
20
24
|
has(k: any): boolean {
|
|
21
25
|
return this.lru.has(k)
|
|
@@ -30,6 +34,6 @@ export class LRUMemoCache implements MemoCache {
|
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
clear(): void {
|
|
33
|
-
this.lru.
|
|
37
|
+
this.lru.clear()
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -13,7 +13,7 @@ import { AjvSchema, AjvSchemaCfg } from './ajvSchema'
|
|
|
13
13
|
* @experimental
|
|
14
14
|
*/
|
|
15
15
|
export function readJsonSchemas(patterns: string | string[], opt?: GlobbyOptions): JsonSchema[] {
|
|
16
|
-
return globby.sync(patterns, opt).map(fileName => JSON.parse(fs.readFileSync(fileName, '
|
|
16
|
+
return globby.sync(patterns, opt).map(fileName => JSON.parse(fs.readFileSync(fileName, 'utf8')))
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -132,7 +132,7 @@ export class AjvSchema<T = unknown> {
|
|
|
132
132
|
cfg: Partial<AjvSchemaCfg> = {},
|
|
133
133
|
): AjvSchema<T> {
|
|
134
134
|
requireFileToExist(filePath)
|
|
135
|
-
const schema = JSON.parse(fs.readFileSync(filePath, '
|
|
135
|
+
const schema = JSON.parse(fs.readFileSync(filePath, 'utf8'))
|
|
136
136
|
return new AjvSchema<T>(schema, cfg)
|
|
137
137
|
}
|
|
138
138
|
|