@naturalcycles/nodejs-lib 15.3.0 → 15.5.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/bin/slack-this.js +1 -1
- package/dist/csv/csvReader.js +1 -1
- package/dist/csv/csvWriter.js +1 -1
- package/dist/diff/tableDiff.js +1 -1
- package/dist/{exec2.d.ts → exec2/exec2.d.ts} +1 -1
- package/dist/{exec2.js → exec2/exec2.js} +4 -4
- package/dist/fs/fs2.js +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/jwt/jwt.service.js +2 -1
- package/dist/script/runScript.d.ts +1 -0
- package/dist/script/runScript.js +6 -6
- package/dist/secret/secrets-decrypt.util.js +1 -1
- package/dist/secret/secrets-encrypt.util.js +1 -1
- package/dist/security/secret.util.js +2 -2
- package/dist/slack/index.d.ts +2 -0
- package/dist/slack/index.js +2 -0
- package/dist/slack/slack.service.js +3 -3
- package/dist/slack/slack.service.model.d.ts +1 -1
- package/dist/stream/ndjson/ndjson.model.js +1 -1
- package/dist/stream/ndjson/ndjsonMap.js +1 -1
- package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +2 -1
- package/dist/stream/ndjson/ndjsonStreamForEach.js +6 -3
- package/dist/stream/pipeline/pipeline.js +2 -2
- package/dist/stream/readable/readableForEach.d.ts +1 -1
- package/dist/stream/readable/readableForEach.js +1 -1
- package/dist/stream/sizeStack.d.ts +1 -1
- package/dist/stream/sizeStack.js +1 -1
- package/dist/stream/transform/transformLimit.d.ts +1 -1
- package/dist/stream/transform/transformLimit.js +2 -1
- package/dist/stream/transform/transformMap.js +3 -3
- package/dist/stream/transform/transformMapSimple.d.ts +1 -1
- package/dist/stream/transform/transformMapSimple.js +1 -1
- package/dist/stream/transform/transformOffset.js +1 -1
- package/dist/stream/transform/transformThrottle.js +1 -1
- package/dist/stream/transform/worker/transformMultiThreaded.js +2 -2
- package/dist/stream/writable/writableForEach.d.ts +1 -1
- package/dist/stream/writable/writableForEach.js +2 -1
- package/dist/stream/writable/writableFork.js +2 -1
- package/dist/string/inspect.js +1 -1
- package/dist/util/buildInfo.util.js +2 -2
- package/dist/util/git2.js +1 -1
- package/dist/validation/ajv/ajvSchema.d.ts +10 -8
- package/dist/validation/ajv/ajvSchema.js +29 -27
- package/dist/validation/ajv/ajvValidationError.d.ts +1 -1
- package/dist/validation/ajv/ajvValidationError.js +1 -1
- package/dist/validation/ajv/getAjv.d.ts +10 -1
- package/dist/validation/ajv/getAjv.js +11 -1
- package/dist/validation/ajv/index.d.ts +0 -1
- package/dist/validation/ajv/index.js +0 -1
- package/dist/validation/joi/joi.validation.error.d.ts +1 -1
- package/dist/validation/joi/joi.validation.error.js +1 -1
- package/dist/validation/joi/joi.validation.util.d.ts +2 -0
- package/dist/validation/joi/joi.validation.util.js +3 -1
- package/dist/validation/joi/string.extensions.js +1 -1
- package/package.json +7 -5
- package/src/bin/slack-this.ts +1 -1
- package/src/csv/csvReader.ts +1 -1
- package/src/csv/csvWriter.ts +1 -1
- package/src/diff/tableDiff.ts +1 -1
- package/src/{exec2.ts → exec2/exec2.ts} +4 -4
- package/src/fs/fs2.ts +1 -1
- package/src/index.ts +0 -3
- package/src/jwt/jwt.service.ts +2 -1
- package/src/script/runScript.ts +6 -8
- package/src/secret/secrets-decrypt.util.ts +1 -1
- package/src/secret/secrets-encrypt.util.ts +1 -1
- package/src/security/secret.util.ts +2 -2
- package/src/slack/index.ts +2 -0
- package/src/slack/slack.service.model.ts +1 -1
- package/src/slack/slack.service.ts +4 -5
- package/src/stream/ndjson/ndjson.model.ts +1 -1
- package/src/stream/ndjson/ndjsonMap.ts +1 -1
- package/src/stream/ndjson/ndjsonStreamForEach.ts +7 -5
- package/src/stream/pipeline/pipeline.ts +2 -2
- package/src/stream/readable/readableForEach.ts +2 -2
- package/src/stream/sizeStack.ts +1 -1
- package/src/stream/transform/transformLimit.ts +2 -1
- package/src/stream/transform/transformMap.ts +3 -3
- package/src/stream/transform/transformMapSimple.ts +1 -1
- package/src/stream/transform/transformOffset.ts +1 -1
- package/src/stream/transform/transformThrottle.ts +1 -1
- package/src/stream/transform/worker/transformMultiThreaded.ts +2 -2
- package/src/stream/writable/writableForEach.ts +2 -2
- package/src/stream/writable/writableFork.ts +3 -3
- package/src/string/inspect.ts +1 -1
- package/src/util/buildInfo.util.ts +2 -2
- package/src/util/git2.ts +1 -1
- package/src/validation/ajv/ajvSchema.ts +43 -33
- package/src/validation/ajv/ajvValidationError.ts +1 -1
- package/src/validation/ajv/getAjv.ts +12 -1
- package/src/validation/ajv/index.ts +0 -1
- package/src/validation/joi/joi.validation.error.ts +1 -1
- package/src/validation/joi/joi.validation.util.ts +3 -1
- package/src/validation/joi/string.extensions.ts +1 -1
- package/dist/validation/ajv/ajv.util.d.ts +0 -21
- package/dist/validation/ajv/ajv.util.js +0 -28
- package/src/validation/ajv/ajv.util.ts +0 -38
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _lazyValue } from '@naturalcycles/js-lib'
|
|
1
2
|
import type { Options } from 'ajv'
|
|
2
3
|
import { Ajv } from 'ajv'
|
|
3
4
|
import ajvFormats from 'ajv-formats'
|
|
@@ -13,12 +14,22 @@ const AJV_OPTIONS: Options = {
|
|
|
13
14
|
coerceTypes: false, // while `false` - it won't mutate your input
|
|
14
15
|
}
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Return cached instance of Ajv with default (recommended) options.
|
|
19
|
+
*
|
|
20
|
+
* This function should be used as much as possible,
|
|
21
|
+
* to benefit from cached Ajv instance.
|
|
22
|
+
*/
|
|
23
|
+
export const getAjv = _lazyValue(createAjv)
|
|
24
|
+
|
|
16
25
|
/**
|
|
17
26
|
* Create Ajv with modified defaults.
|
|
18
27
|
*
|
|
28
|
+
* !!! Please note that this function is EXPENSIVE computationally !!!
|
|
29
|
+
*
|
|
19
30
|
* https://ajv.js.org/options.html
|
|
20
31
|
*/
|
|
21
|
-
export function
|
|
32
|
+
export function createAjv(opt?: Options): Ajv {
|
|
22
33
|
const ajv = new Ajv({
|
|
23
34
|
...AJV_OPTIONS,
|
|
24
35
|
...opt,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { _hb, _isObject } from '@naturalcycles/js-lib'
|
|
10
|
-
import { _truncateMiddle } from '@naturalcycles/js-lib/string'
|
|
10
|
+
import { _truncateMiddle } from '@naturalcycles/js-lib/string/string.util.js'
|
|
11
11
|
import type { AnySchema, ValidationError, ValidationOptions } from 'joi'
|
|
12
12
|
import type { JoiValidationErrorData } from './joi.validation.error.js'
|
|
13
13
|
import { JoiValidationError } from './joi.validation.error.js'
|
|
@@ -70,6 +70,8 @@ export function validate<T>(
|
|
|
70
70
|
* Returns JoiValidationResult with converted value and error (if any).
|
|
71
71
|
* Does not throw.
|
|
72
72
|
*
|
|
73
|
+
* Joi does NOT mutate the input.
|
|
74
|
+
*
|
|
73
75
|
* If `schema` is undefined - returns value as is.
|
|
74
76
|
*/
|
|
75
77
|
export function getValidationResult<T>(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { localTime } from '@naturalcycles/js-lib/datetime'
|
|
1
|
+
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
|
|
2
2
|
import type { IsoDate } from '@naturalcycles/js-lib/types'
|
|
3
3
|
import type Joi from 'joi'
|
|
4
4
|
import type { Extension, StringSchema as JoiStringSchema } from 'joi'
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { JsonSchema } from '@naturalcycles/js-lib/json-schema';
|
|
2
|
-
import type { GlobOptions } from 'tinyglobby';
|
|
3
|
-
import type { AjvSchemaCfg } from './ajvSchema.js';
|
|
4
|
-
import { AjvSchema } from './ajvSchema.js';
|
|
5
|
-
/**
|
|
6
|
-
* Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
|
|
7
|
-
* E.g `someDir/**\/*.schema.json`
|
|
8
|
-
*
|
|
9
|
-
* Returns them as an array of JsonSchema.
|
|
10
|
-
*
|
|
11
|
-
* @experimental
|
|
12
|
-
*/
|
|
13
|
-
export declare function readJsonSchemas(patterns: string | string[], opt?: Omit<GlobOptions, 'patterns'>): JsonSchema[];
|
|
14
|
-
/**
|
|
15
|
-
* Reads json schemas from given dir (glob pattern).
|
|
16
|
-
* Creates new AjvSchema for each of them (ajv validates them upon creation).
|
|
17
|
-
* Passes `schemas` option to ajv, so, schemas may $ref each other and it'll be fine.
|
|
18
|
-
*
|
|
19
|
-
* @experimental
|
|
20
|
-
*/
|
|
21
|
-
export declare function readAjvSchemas(patterns: string | string[], cfg?: AjvSchemaCfg): AjvSchema[];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { globSync } from 'tinyglobby';
|
|
2
|
-
import { fs2 } from '../../fs/fs2.js';
|
|
3
|
-
import { AjvSchema } from './ajvSchema.js';
|
|
4
|
-
/**
|
|
5
|
-
* Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
|
|
6
|
-
* E.g `someDir/**\/*.schema.json`
|
|
7
|
-
*
|
|
8
|
-
* Returns them as an array of JsonSchema.
|
|
9
|
-
*
|
|
10
|
-
* @experimental
|
|
11
|
-
*/
|
|
12
|
-
export function readJsonSchemas(patterns, opt) {
|
|
13
|
-
return globSync(patterns, opt).map(fileName => fs2.readJson(fileName));
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Reads json schemas from given dir (glob pattern).
|
|
17
|
-
* Creates new AjvSchema for each of them (ajv validates them upon creation).
|
|
18
|
-
* Passes `schemas` option to ajv, so, schemas may $ref each other and it'll be fine.
|
|
19
|
-
*
|
|
20
|
-
* @experimental
|
|
21
|
-
*/
|
|
22
|
-
export function readAjvSchemas(patterns, cfg) {
|
|
23
|
-
const schemas = readJsonSchemas(patterns);
|
|
24
|
-
return schemas.map(schema => AjvSchema.create(schema, {
|
|
25
|
-
schemas,
|
|
26
|
-
...cfg,
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { JsonSchema } from '@naturalcycles/js-lib/json-schema'
|
|
2
|
-
import type { GlobOptions } from 'tinyglobby'
|
|
3
|
-
import { globSync } from 'tinyglobby'
|
|
4
|
-
import { fs2 } from '../../fs/fs2.js'
|
|
5
|
-
import type { AjvSchemaCfg } from './ajvSchema.js'
|
|
6
|
-
import { AjvSchema } from './ajvSchema.js'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
|
|
10
|
-
* E.g `someDir/**\/*.schema.json`
|
|
11
|
-
*
|
|
12
|
-
* Returns them as an array of JsonSchema.
|
|
13
|
-
*
|
|
14
|
-
* @experimental
|
|
15
|
-
*/
|
|
16
|
-
export function readJsonSchemas(
|
|
17
|
-
patterns: string | string[],
|
|
18
|
-
opt?: Omit<GlobOptions, 'patterns'>,
|
|
19
|
-
): JsonSchema[] {
|
|
20
|
-
return globSync(patterns, opt).map(fileName => fs2.readJson(fileName))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Reads json schemas from given dir (glob pattern).
|
|
25
|
-
* Creates new AjvSchema for each of them (ajv validates them upon creation).
|
|
26
|
-
* Passes `schemas` option to ajv, so, schemas may $ref each other and it'll be fine.
|
|
27
|
-
*
|
|
28
|
-
* @experimental
|
|
29
|
-
*/
|
|
30
|
-
export function readAjvSchemas(patterns: string | string[], cfg?: AjvSchemaCfg): AjvSchema[] {
|
|
31
|
-
const schemas = readJsonSchemas(patterns)
|
|
32
|
-
return schemas.map(schema =>
|
|
33
|
-
AjvSchema.create(schema, {
|
|
34
|
-
schemas,
|
|
35
|
-
...cfg,
|
|
36
|
-
}),
|
|
37
|
-
)
|
|
38
|
-
}
|