@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.
Files changed (98) hide show
  1. package/dist/bin/slack-this.js +1 -1
  2. package/dist/csv/csvReader.js +1 -1
  3. package/dist/csv/csvWriter.js +1 -1
  4. package/dist/diff/tableDiff.js +1 -1
  5. package/dist/{exec2.d.ts → exec2/exec2.d.ts} +1 -1
  6. package/dist/{exec2.js → exec2/exec2.js} +4 -4
  7. package/dist/fs/fs2.js +1 -1
  8. package/dist/index.d.ts +0 -3
  9. package/dist/index.js +0 -3
  10. package/dist/jwt/jwt.service.js +2 -1
  11. package/dist/script/runScript.d.ts +1 -0
  12. package/dist/script/runScript.js +6 -6
  13. package/dist/secret/secrets-decrypt.util.js +1 -1
  14. package/dist/secret/secrets-encrypt.util.js +1 -1
  15. package/dist/security/secret.util.js +2 -2
  16. package/dist/slack/index.d.ts +2 -0
  17. package/dist/slack/index.js +2 -0
  18. package/dist/slack/slack.service.js +3 -3
  19. package/dist/slack/slack.service.model.d.ts +1 -1
  20. package/dist/stream/ndjson/ndjson.model.js +1 -1
  21. package/dist/stream/ndjson/ndjsonMap.js +1 -1
  22. package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +2 -1
  23. package/dist/stream/ndjson/ndjsonStreamForEach.js +6 -3
  24. package/dist/stream/pipeline/pipeline.js +2 -2
  25. package/dist/stream/readable/readableForEach.d.ts +1 -1
  26. package/dist/stream/readable/readableForEach.js +1 -1
  27. package/dist/stream/sizeStack.d.ts +1 -1
  28. package/dist/stream/sizeStack.js +1 -1
  29. package/dist/stream/transform/transformLimit.d.ts +1 -1
  30. package/dist/stream/transform/transformLimit.js +2 -1
  31. package/dist/stream/transform/transformMap.js +3 -3
  32. package/dist/stream/transform/transformMapSimple.d.ts +1 -1
  33. package/dist/stream/transform/transformMapSimple.js +1 -1
  34. package/dist/stream/transform/transformOffset.js +1 -1
  35. package/dist/stream/transform/transformThrottle.js +1 -1
  36. package/dist/stream/transform/worker/transformMultiThreaded.js +2 -2
  37. package/dist/stream/writable/writableForEach.d.ts +1 -1
  38. package/dist/stream/writable/writableForEach.js +2 -1
  39. package/dist/stream/writable/writableFork.js +2 -1
  40. package/dist/string/inspect.js +1 -1
  41. package/dist/util/buildInfo.util.js +2 -2
  42. package/dist/util/git2.js +1 -1
  43. package/dist/validation/ajv/ajvSchema.d.ts +10 -8
  44. package/dist/validation/ajv/ajvSchema.js +29 -27
  45. package/dist/validation/ajv/ajvValidationError.d.ts +1 -1
  46. package/dist/validation/ajv/ajvValidationError.js +1 -1
  47. package/dist/validation/ajv/getAjv.d.ts +10 -1
  48. package/dist/validation/ajv/getAjv.js +11 -1
  49. package/dist/validation/ajv/index.d.ts +0 -1
  50. package/dist/validation/ajv/index.js +0 -1
  51. package/dist/validation/joi/joi.validation.error.d.ts +1 -1
  52. package/dist/validation/joi/joi.validation.error.js +1 -1
  53. package/dist/validation/joi/joi.validation.util.d.ts +2 -0
  54. package/dist/validation/joi/joi.validation.util.js +3 -1
  55. package/dist/validation/joi/string.extensions.js +1 -1
  56. package/package.json +7 -5
  57. package/src/bin/slack-this.ts +1 -1
  58. package/src/csv/csvReader.ts +1 -1
  59. package/src/csv/csvWriter.ts +1 -1
  60. package/src/diff/tableDiff.ts +1 -1
  61. package/src/{exec2.ts → exec2/exec2.ts} +4 -4
  62. package/src/fs/fs2.ts +1 -1
  63. package/src/index.ts +0 -3
  64. package/src/jwt/jwt.service.ts +2 -1
  65. package/src/script/runScript.ts +6 -8
  66. package/src/secret/secrets-decrypt.util.ts +1 -1
  67. package/src/secret/secrets-encrypt.util.ts +1 -1
  68. package/src/security/secret.util.ts +2 -2
  69. package/src/slack/index.ts +2 -0
  70. package/src/slack/slack.service.model.ts +1 -1
  71. package/src/slack/slack.service.ts +4 -5
  72. package/src/stream/ndjson/ndjson.model.ts +1 -1
  73. package/src/stream/ndjson/ndjsonMap.ts +1 -1
  74. package/src/stream/ndjson/ndjsonStreamForEach.ts +7 -5
  75. package/src/stream/pipeline/pipeline.ts +2 -2
  76. package/src/stream/readable/readableForEach.ts +2 -2
  77. package/src/stream/sizeStack.ts +1 -1
  78. package/src/stream/transform/transformLimit.ts +2 -1
  79. package/src/stream/transform/transformMap.ts +3 -3
  80. package/src/stream/transform/transformMapSimple.ts +1 -1
  81. package/src/stream/transform/transformOffset.ts +1 -1
  82. package/src/stream/transform/transformThrottle.ts +1 -1
  83. package/src/stream/transform/worker/transformMultiThreaded.ts +2 -2
  84. package/src/stream/writable/writableForEach.ts +2 -2
  85. package/src/stream/writable/writableFork.ts +3 -3
  86. package/src/string/inspect.ts +1 -1
  87. package/src/util/buildInfo.util.ts +2 -2
  88. package/src/util/git2.ts +1 -1
  89. package/src/validation/ajv/ajvSchema.ts +43 -33
  90. package/src/validation/ajv/ajvValidationError.ts +1 -1
  91. package/src/validation/ajv/getAjv.ts +12 -1
  92. package/src/validation/ajv/index.ts +0 -1
  93. package/src/validation/joi/joi.validation.error.ts +1 -1
  94. package/src/validation/joi/joi.validation.util.ts +3 -1
  95. package/src/validation/joi/string.extensions.ts +1 -1
  96. package/dist/validation/ajv/ajv.util.d.ts +0 -21
  97. package/dist/validation/ajv/ajv.util.js +0 -28
  98. 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 getAjv(opt?: Options): Ajv {
32
+ export function createAjv(opt?: Options): Ajv {
22
33
  const ajv = new Ajv({
23
34
  ...AJV_OPTIONS,
24
35
  ...opt,
@@ -1,6 +1,5 @@
1
1
  import Ajv from 'ajv'
2
2
 
3
- export * from './ajv.util.js'
4
3
  export * from './ajvSchema.js'
5
4
  export * from './ajvValidationError.js'
6
5
  export * from './getAjv.js'
@@ -1,5 +1,5 @@
1
1
  import type { ErrorData } from '@naturalcycles/js-lib/error'
2
- import { AppError } from '@naturalcycles/js-lib/error'
2
+ import { AppError } from '@naturalcycles/js-lib/error/error.util.js'
3
3
  import type { ValidationErrorItem } from 'joi'
4
4
 
5
5
  /**
@@ -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
- }