@naturalcycles/nodejs-lib 12.53.0 → 12.54.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/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/dist/script/index.d.ts +5 -0
- package/dist/script/index.js +6 -5
- package/dist/slack/slack.service.d.ts +11 -2
- package/dist/slack/slack.service.js +15 -0
- package/dist/slack/slack.service.model.d.ts +2 -2
- package/dist/validation/ajv/ajvSchema.d.ts +5 -1
- package/dist/validation/ajv/ajvSchema.js +2 -1
- package/package.json +1 -1
- package/src/diff/tableDiff.ts +2 -2
- package/src/index.ts +3 -0
- package/src/script/index.ts +14 -5
- package/src/slack/slack.service.model.ts +2 -2
- package/src/slack/slack.service.ts +38 -2
- package/src/validation/ajv/ajvSchema.ts +8 -1
package/dist/index.d.ts
CHANGED
|
@@ -65,5 +65,6 @@ import { anyObjectSchema, anySchema, arraySchema, oneOfSchema, binarySchema, boo
|
|
|
65
65
|
import { JoiValidationError, JoiValidationErrorData } from './validation/joi/joi.validation.error';
|
|
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
|
-
|
|
69
|
-
export {
|
|
68
|
+
import { runScript, RunScriptOptions } from './script';
|
|
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, TransformLogProgressOptions, TransformMultiThreadedOptions, WorkerClassInterface, WorkerInput, WorkerOutput, TableDiffOptions, InspectAnyOptions, Got, GetGotOptions, AfterResponseHook, BeforeErrorHook, BeforeRequestHook, AjvValidationOptions, AjvSchemaCfg, AjvValidationErrorData, SanitizeHTMLOptions, };
|
|
70
|
+
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, runScript, };
|
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.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;
|
|
5
|
+
exports.runScript = 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");
|
|
@@ -191,3 +191,5 @@ Object.defineProperty(exports, "undefinedIfInvalid", { enumerable: true, get: fu
|
|
|
191
191
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return joi_validation_util_1.validate; } });
|
|
192
192
|
const sanitize_util_1 = require("./validation/sanitize.util");
|
|
193
193
|
Object.defineProperty(exports, "sanitizeHTML", { enumerable: true, get: function () { return sanitize_util_1.sanitizeHTML; } });
|
|
194
|
+
const script_1 = require("./script");
|
|
195
|
+
Object.defineProperty(exports, "runScript", { enumerable: true, get: function () { return script_1.runScript; } });
|
package/dist/script/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CommonLogger } from '@naturalcycles/js-lib';
|
|
1
2
|
export interface RunScriptOptions {
|
|
2
3
|
/**
|
|
3
4
|
* @default false
|
|
@@ -5,6 +6,10 @@ export interface RunScriptOptions {
|
|
|
5
6
|
* Currently it exists because of `jest --maxWorkers=1` behavior. To be investigated more..
|
|
6
7
|
*/
|
|
7
8
|
noExit?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Default to `console`
|
|
11
|
+
*/
|
|
12
|
+
logger?: CommonLogger;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
* Use it in your top-level scripts like this:
|
package/dist/script/index.js
CHANGED
|
@@ -18,23 +18,24 @@ exports.runScript = void 0;
|
|
|
18
18
|
* This function is kept light, dependency-free, exported separately.
|
|
19
19
|
*/
|
|
20
20
|
function runScript(fn, opt = {}) {
|
|
21
|
+
const { logger = console, noExit } = opt;
|
|
21
22
|
process.on('uncaughtException', err => {
|
|
22
|
-
|
|
23
|
+
logger.error('uncaughtException:', err);
|
|
23
24
|
});
|
|
24
25
|
process.on('unhandledRejection', err => {
|
|
25
|
-
|
|
26
|
+
logger.error('unhandledRejection:', err);
|
|
26
27
|
});
|
|
27
28
|
void (async () => {
|
|
28
29
|
try {
|
|
29
30
|
await fn();
|
|
30
|
-
if (!
|
|
31
|
+
if (!noExit) {
|
|
31
32
|
setImmediate(() => process.exit(0));
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
catch (err) {
|
|
35
|
-
|
|
36
|
+
logger.error('runScript error:', err);
|
|
36
37
|
process.exitCode = 1;
|
|
37
|
-
if (!
|
|
38
|
+
if (!noExit) {
|
|
38
39
|
setImmediate(() => process.exit(1));
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyObject, CommonLogger, CommonLogLevel } from '@naturalcycles/js-lib';
|
|
2
2
|
import { SlackAttachmentField, SlackMessage, SlackServiceCfg } from './slack.service.model';
|
|
3
3
|
/**
|
|
4
4
|
* Has 2 main methods:
|
|
@@ -20,6 +20,15 @@ export declare class SlackService<CTX = any> {
|
|
|
20
20
|
*/
|
|
21
21
|
log(...items: any[]): Promise<void>;
|
|
22
22
|
send(input: SlackMessage<CTX> | string, ctx?: CTX): Promise<void>;
|
|
23
|
-
kvToFields(kv:
|
|
23
|
+
kvToFields(kv: AnyObject): SlackAttachmentField[];
|
|
24
|
+
/**
|
|
25
|
+
* Returns a CommonLogger implementation based on this SlackService instance.
|
|
26
|
+
*/
|
|
27
|
+
getCommonLogger(opt: {
|
|
28
|
+
minLogLevel: CommonLogLevel;
|
|
29
|
+
logChannel?: string;
|
|
30
|
+
warnChannel?: string;
|
|
31
|
+
errorChannel?: string;
|
|
32
|
+
}): CommonLogger;
|
|
24
33
|
}
|
|
25
34
|
export declare function slackDefaultMessagePrefixHook(msg: SlackMessage): string[];
|
|
@@ -110,6 +110,21 @@ class SlackService {
|
|
|
110
110
|
short: String(v).length < 80,
|
|
111
111
|
}));
|
|
112
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns a CommonLogger implementation based on this SlackService instance.
|
|
115
|
+
*/
|
|
116
|
+
getCommonLogger(opt) {
|
|
117
|
+
const { minLogLevel = 'log', logChannel, warnChannel, errorChannel } = opt;
|
|
118
|
+
const defaultChannel = this.cfg.defaults?.channel || DEFAULTS.channel;
|
|
119
|
+
const q = new js_lib_1.PQueue({
|
|
120
|
+
concurrency: 1,
|
|
121
|
+
});
|
|
122
|
+
return (0, js_lib_1.commonLoggerMinLevel)({
|
|
123
|
+
log: (...args) => q.push(() => this.send({ items: args, channel: logChannel || defaultChannel })),
|
|
124
|
+
warn: (...args) => q.push(() => this.send({ items: args, channel: warnChannel || defaultChannel })),
|
|
125
|
+
error: (...args) => q.push(() => this.send({ items: args, channel: errorChannel || defaultChannel })),
|
|
126
|
+
}, minLogLevel);
|
|
127
|
+
}
|
|
113
128
|
}
|
|
114
129
|
exports.SlackService = SlackService;
|
|
115
130
|
function slackDefaultMessagePrefixHook(msg) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyObject, CommonLogger } from '@naturalcycles/js-lib';
|
|
2
2
|
import { InspectAnyOptions } from '..';
|
|
3
3
|
/**
|
|
4
4
|
* Properties that exists both in SlackApiBody (as per Slack API) and SlackMessage (our abstraction).
|
|
@@ -39,7 +39,7 @@ export interface SlackMessage<CTX = any> extends SlackMessageProps {
|
|
|
39
39
|
/**
|
|
40
40
|
* Keys-values will be rendered as MessageAttachment with Fields
|
|
41
41
|
*/
|
|
42
|
-
kv?:
|
|
42
|
+
kv?: AnyObject;
|
|
43
43
|
/**
|
|
44
44
|
* If specified - adds @name1, @name2 in the end of the message
|
|
45
45
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
|
|
1
|
+
import { JsonSchema, JsonSchemaBuilder, CommonLogger } from '@naturalcycles/js-lib';
|
|
2
2
|
import Ajv from 'ajv';
|
|
3
3
|
import { AjvValidationError } from './ajvValidationError';
|
|
4
4
|
export interface AjvValidationOptions {
|
|
@@ -37,6 +37,10 @@ export interface AjvSchemaCfg {
|
|
|
37
37
|
* @default true
|
|
38
38
|
*/
|
|
39
39
|
logErrors: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Default to `console`
|
|
42
|
+
*/
|
|
43
|
+
logger: CommonLogger;
|
|
40
44
|
/**
|
|
41
45
|
* Option of Ajv.
|
|
42
46
|
* If set to true - will mutate your input objects!
|
|
@@ -17,6 +17,7 @@ class AjvSchema {
|
|
|
17
17
|
this.schema = schema;
|
|
18
18
|
this.cfg = {
|
|
19
19
|
logErrors: true,
|
|
20
|
+
logger: console,
|
|
20
21
|
separator: '\n',
|
|
21
22
|
...cfg,
|
|
22
23
|
ajv: cfg.ajv ||
|
|
@@ -89,7 +90,7 @@ class AjvSchema {
|
|
|
89
90
|
const strValue = (0, index_1.inspectAny)(obj, { maxLen: 1000 });
|
|
90
91
|
message = [message, 'Input: ' + strValue].join(separator);
|
|
91
92
|
if (logErrors) {
|
|
92
|
-
|
|
93
|
+
this.cfg.logger.error(errors);
|
|
93
94
|
}
|
|
94
95
|
return new ajvValidationError_1.AjvValidationError(message, (0, js_lib_1._filterNullishValues)({
|
|
95
96
|
errors,
|
package/package.json
CHANGED
package/src/diff/tableDiff.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _truncate, AnyObject } from '@naturalcycles/js-lib'
|
|
2
2
|
|
|
3
3
|
export interface TableDiffOptions {
|
|
4
4
|
/**
|
|
@@ -37,7 +37,7 @@ export interface TableDiffOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
export function tableDiff(a: AnyObject, b: AnyObject, opt: TableDiffOptions = {}): void {
|
|
39
39
|
const { maxFieldLen, aTitle = 'a', bTitle = 'b' } = opt
|
|
40
|
-
const diff:
|
|
40
|
+
const diff: AnyObject = {}
|
|
41
41
|
|
|
42
42
|
if (a && b && a !== b) {
|
|
43
43
|
new Set([...Object.keys(a), ...Object.keys(b)]).forEach(k => {
|
package/src/index.ts
CHANGED
|
@@ -173,8 +173,10 @@ import {
|
|
|
173
173
|
validate,
|
|
174
174
|
} from './validation/joi/joi.validation.util'
|
|
175
175
|
import { sanitizeHTML, SanitizeHTMLOptions } from './validation/sanitize.util'
|
|
176
|
+
import { runScript, RunScriptOptions } from './script'
|
|
176
177
|
|
|
177
178
|
export type {
|
|
179
|
+
RunScriptOptions,
|
|
178
180
|
JoiValidationErrorData,
|
|
179
181
|
JoiValidationResult,
|
|
180
182
|
ValidationErrorItem,
|
|
@@ -352,4 +354,5 @@ export {
|
|
|
352
354
|
readAjvSchemas,
|
|
353
355
|
hasColors,
|
|
354
356
|
sanitizeHTML,
|
|
357
|
+
runScript,
|
|
355
358
|
}
|
package/src/script/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { CommonLogger } from '@naturalcycles/js-lib'
|
|
2
|
+
|
|
1
3
|
export interface RunScriptOptions {
|
|
2
4
|
/**
|
|
3
5
|
* @default false
|
|
@@ -5,6 +7,11 @@ export interface RunScriptOptions {
|
|
|
5
7
|
* Currently it exists because of `jest --maxWorkers=1` behavior. To be investigated more..
|
|
6
8
|
*/
|
|
7
9
|
noExit?: boolean
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Default to `console`
|
|
13
|
+
*/
|
|
14
|
+
logger?: CommonLogger
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
/**
|
|
@@ -24,24 +31,26 @@ export interface RunScriptOptions {
|
|
|
24
31
|
* This function is kept light, dependency-free, exported separately.
|
|
25
32
|
*/
|
|
26
33
|
export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
|
|
34
|
+
const { logger = console, noExit } = opt
|
|
35
|
+
|
|
27
36
|
process.on('uncaughtException', err => {
|
|
28
|
-
|
|
37
|
+
logger.error('uncaughtException:', err)
|
|
29
38
|
})
|
|
30
39
|
process.on('unhandledRejection', err => {
|
|
31
|
-
|
|
40
|
+
logger.error('unhandledRejection:', err)
|
|
32
41
|
})
|
|
33
42
|
|
|
34
43
|
void (async () => {
|
|
35
44
|
try {
|
|
36
45
|
await fn()
|
|
37
46
|
|
|
38
|
-
if (!
|
|
47
|
+
if (!noExit) {
|
|
39
48
|
setImmediate(() => process.exit(0))
|
|
40
49
|
}
|
|
41
50
|
} catch (err) {
|
|
42
|
-
|
|
51
|
+
logger.error('runScript error:', err)
|
|
43
52
|
process.exitCode = 1
|
|
44
|
-
if (!
|
|
53
|
+
if (!noExit) {
|
|
45
54
|
setImmediate(() => process.exit(1))
|
|
46
55
|
}
|
|
47
56
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyObject, CommonLogger } from '@naturalcycles/js-lib'
|
|
2
2
|
import { InspectAnyOptions } from '..'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -47,7 +47,7 @@ export interface SlackMessage<CTX = any> extends SlackMessageProps {
|
|
|
47
47
|
/**
|
|
48
48
|
* Keys-values will be rendered as MessageAttachment with Fields
|
|
49
49
|
*/
|
|
50
|
-
kv?:
|
|
50
|
+
kv?: AnyObject
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* If specified - adds @name1, @name2 in the end of the message
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
_omit,
|
|
3
|
+
AnyObject,
|
|
4
|
+
CommonLogger,
|
|
5
|
+
commonLoggerMinLevel,
|
|
6
|
+
CommonLogLevel,
|
|
7
|
+
PQueue,
|
|
8
|
+
} from '@naturalcycles/js-lib'
|
|
2
9
|
import { dayjs } from '@naturalcycles/time-lib'
|
|
3
10
|
import got from 'got'
|
|
4
11
|
import { inspectAny, InspectAnyOptions } from '..'
|
|
@@ -126,13 +133,42 @@ export class SlackService<CTX = any> {
|
|
|
126
133
|
})
|
|
127
134
|
}
|
|
128
135
|
|
|
129
|
-
kvToFields(kv:
|
|
136
|
+
kvToFields(kv: AnyObject): SlackAttachmentField[] {
|
|
130
137
|
return Object.entries(kv).map(([k, v]) => ({
|
|
131
138
|
title: k,
|
|
132
139
|
value: String(v),
|
|
133
140
|
short: String(v).length < 80,
|
|
134
141
|
}))
|
|
135
142
|
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Returns a CommonLogger implementation based on this SlackService instance.
|
|
146
|
+
*/
|
|
147
|
+
getCommonLogger(opt: {
|
|
148
|
+
minLogLevel: CommonLogLevel
|
|
149
|
+
logChannel?: string
|
|
150
|
+
warnChannel?: string
|
|
151
|
+
errorChannel?: string
|
|
152
|
+
}): CommonLogger {
|
|
153
|
+
const { minLogLevel = 'log', logChannel, warnChannel, errorChannel } = opt
|
|
154
|
+
const defaultChannel = this.cfg.defaults?.channel || DEFAULTS.channel!
|
|
155
|
+
|
|
156
|
+
const q = new PQueue({
|
|
157
|
+
concurrency: 1,
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
return commonLoggerMinLevel(
|
|
161
|
+
{
|
|
162
|
+
log: (...args) =>
|
|
163
|
+
q.push(() => this.send({ items: args, channel: logChannel || defaultChannel })),
|
|
164
|
+
warn: (...args) =>
|
|
165
|
+
q.push(() => this.send({ items: args, channel: warnChannel || defaultChannel })),
|
|
166
|
+
error: (...args) =>
|
|
167
|
+
q.push(() => this.send({ items: args, channel: errorChannel || defaultChannel })),
|
|
168
|
+
},
|
|
169
|
+
minLogLevel,
|
|
170
|
+
)
|
|
171
|
+
}
|
|
136
172
|
}
|
|
137
173
|
|
|
138
174
|
export function slackDefaultMessagePrefixHook(msg: SlackMessage): string[] {
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
_filterNullishValues,
|
|
7
7
|
_isObject,
|
|
8
8
|
_substringBefore,
|
|
9
|
+
CommonLogger,
|
|
9
10
|
} from '@naturalcycles/js-lib'
|
|
10
11
|
import Ajv, { ValidateFunction } from 'ajv'
|
|
11
12
|
import { inspectAny, requireFileToExist } from '../../index'
|
|
@@ -56,6 +57,11 @@ export interface AjvSchemaCfg {
|
|
|
56
57
|
*/
|
|
57
58
|
logErrors: boolean
|
|
58
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Default to `console`
|
|
62
|
+
*/
|
|
63
|
+
logger: CommonLogger
|
|
64
|
+
|
|
59
65
|
/**
|
|
60
66
|
* Option of Ajv.
|
|
61
67
|
* If set to true - will mutate your input objects!
|
|
@@ -76,6 +82,7 @@ export class AjvSchema<T = unknown> {
|
|
|
76
82
|
private constructor(public schema: JsonSchema<T>, cfg: Partial<AjvSchemaCfg> = {}) {
|
|
77
83
|
this.cfg = {
|
|
78
84
|
logErrors: true,
|
|
85
|
+
logger: console,
|
|
79
86
|
separator: '\n',
|
|
80
87
|
...cfg,
|
|
81
88
|
ajv:
|
|
@@ -168,7 +175,7 @@ export class AjvSchema<T = unknown> {
|
|
|
168
175
|
message = [message, 'Input: ' + strValue].join(separator)
|
|
169
176
|
|
|
170
177
|
if (logErrors) {
|
|
171
|
-
|
|
178
|
+
this.cfg.logger.error(errors)
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
return new AjvValidationError(
|