@naturalcycles/nodejs-lib 15.2.0 → 15.4.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 (157) hide show
  1. package/dist/bin/slack-this.js +1 -1
  2. package/dist/cache/lruMemoCache.d.ts +1 -1
  3. package/dist/csv/csvReader.d.ts +1 -1
  4. package/dist/csv/csvReader.js +1 -1
  5. package/dist/csv/csvWriter.d.ts +1 -1
  6. package/dist/csv/csvWriter.js +1 -1
  7. package/dist/csv/transformToCSV.d.ts +1 -1
  8. package/dist/diff/tableDiff.d.ts +1 -1
  9. package/dist/diff/tableDiff.js +1 -1
  10. package/dist/{exec2.d.ts → exec2/exec2.d.ts} +2 -2
  11. package/dist/{exec2.js → exec2/exec2.js} +4 -3
  12. package/dist/fs/fs2.js +1 -1
  13. package/dist/fs/json2env.d.ts +1 -1
  14. package/dist/fs/kpy.js +1 -1
  15. package/dist/index.d.ts +0 -3
  16. package/dist/index.js +0 -3
  17. package/dist/jwt/jwt.service.d.ts +2 -1
  18. package/dist/jwt/jwt.service.js +1 -1
  19. package/dist/log/log.util.d.ts +1 -1
  20. package/dist/log/log.util.js +1 -1
  21. package/dist/script/runScript.d.ts +2 -1
  22. package/dist/script/runScript.js +6 -5
  23. package/dist/secret/secrets-decrypt.util.js +1 -1
  24. package/dist/secret/secrets-encrypt.util.js +1 -1
  25. package/dist/security/crypto.util.d.ts +1 -1
  26. package/dist/security/crypto.util.js +1 -1
  27. package/dist/security/hash.util.d.ts +1 -1
  28. package/dist/security/secret.util.d.ts +1 -1
  29. package/dist/security/secret.util.js +2 -1
  30. package/dist/slack/index.d.ts +2 -0
  31. package/dist/slack/index.js +2 -0
  32. package/dist/slack/slack.service.d.ts +2 -1
  33. package/dist/slack/slack.service.js +5 -1
  34. package/dist/slack/slack.service.model.d.ts +3 -2
  35. package/dist/stream/ndjson/ndjson.model.js +2 -1
  36. package/dist/stream/ndjson/ndjsonMap.d.ts +1 -1
  37. package/dist/stream/ndjson/ndjsonMap.js +1 -1
  38. package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +3 -2
  39. package/dist/stream/ndjson/ndjsonStreamForEach.js +6 -3
  40. package/dist/stream/ndjson/transformJsonParse.d.ts +1 -1
  41. package/dist/stream/ndjson/transformToNDJson.js +1 -1
  42. package/dist/stream/pipeline/pipeline.d.ts +1 -1
  43. package/dist/stream/pipeline/pipeline.js +2 -1
  44. package/dist/stream/progressLogger.d.ts +2 -1
  45. package/dist/stream/progressLogger.js +3 -1
  46. package/dist/stream/readable/readableForEach.d.ts +2 -2
  47. package/dist/stream/readable/readableForEach.js +2 -2
  48. package/dist/stream/readable/readableFromArray.d.ts +1 -1
  49. package/dist/stream/readable/readableFromArray.js +1 -1
  50. package/dist/stream/sizeStack.d.ts +2 -2
  51. package/dist/stream/sizeStack.js +2 -1
  52. package/dist/stream/stream.model.d.ts +1 -1
  53. package/dist/stream/stream.util.d.ts +1 -1
  54. package/dist/stream/transform/transformFilter.d.ts +1 -1
  55. package/dist/stream/transform/transformLimit.d.ts +2 -2
  56. package/dist/stream/transform/transformLimit.js +2 -1
  57. package/dist/stream/transform/transformMap.d.ts +3 -2
  58. package/dist/stream/transform/transformMap.js +6 -1
  59. package/dist/stream/transform/transformMapSimple.d.ts +3 -2
  60. package/dist/stream/transform/transformMapSimple.js +1 -1
  61. package/dist/stream/transform/transformMapSync.d.ts +4 -2
  62. package/dist/stream/transform/transformMapSync.js +2 -1
  63. package/dist/stream/transform/transformOffset.js +1 -1
  64. package/dist/stream/transform/transformTap.d.ts +2 -1
  65. package/dist/stream/transform/transformThrottle.d.ts +1 -1
  66. package/dist/stream/transform/transformThrottle.js +2 -1
  67. package/dist/stream/transform/worker/transformMultiThreaded.d.ts +1 -1
  68. package/dist/stream/transform/worker/transformMultiThreaded.js +2 -1
  69. package/dist/stream/writable/writableForEach.d.ts +2 -2
  70. package/dist/stream/writable/writableForEach.js +3 -2
  71. package/dist/stream/writable/writableFork.js +2 -1
  72. package/dist/stream/writable/writableVoid.d.ts +1 -1
  73. package/dist/string/inspect.d.ts +1 -1
  74. package/dist/string/inspect.js +1 -1
  75. package/dist/util/buildInfo.util.d.ts +2 -1
  76. package/dist/util/buildInfo.util.js +2 -1
  77. package/dist/util/env.util.d.ts +1 -1
  78. package/dist/util/git2.d.ts +1 -1
  79. package/dist/util/git2.js +1 -1
  80. package/dist/validation/ajv/ajvSchema.d.ts +11 -9
  81. package/dist/validation/ajv/ajvSchema.js +32 -27
  82. package/dist/validation/ajv/ajvValidationError.d.ts +2 -2
  83. package/dist/validation/ajv/ajvValidationError.js +1 -1
  84. package/dist/validation/ajv/getAjv.d.ts +10 -1
  85. package/dist/validation/ajv/getAjv.js +11 -1
  86. package/dist/validation/ajv/index.d.ts +0 -1
  87. package/dist/validation/ajv/index.js +0 -1
  88. package/dist/validation/joi/joi.shared.schemas.d.ts +2 -2
  89. package/dist/validation/joi/joi.validation.error.d.ts +2 -2
  90. package/dist/validation/joi/joi.validation.error.js +1 -1
  91. package/dist/validation/joi/joi.validation.util.d.ts +2 -0
  92. package/dist/validation/joi/joi.validation.util.js +4 -1
  93. package/dist/validation/joi/string.extensions.d.ts +1 -1
  94. package/dist/validation/joi/string.extensions.js +1 -1
  95. package/package.json +5 -3
  96. package/src/bin/generate-build-info.ts +1 -1
  97. package/src/bin/slack-this.ts +1 -1
  98. package/src/cache/lruMemoCache.ts +1 -1
  99. package/src/csv/csvReader.ts +2 -2
  100. package/src/csv/csvWriter.ts +2 -2
  101. package/src/csv/transformToCSV.ts +1 -1
  102. package/src/diff/tableDiff.ts +2 -2
  103. package/src/{exec2.ts → exec2/exec2.ts} +9 -8
  104. package/src/fs/fs2.ts +1 -1
  105. package/src/fs/json2env.ts +1 -1
  106. package/src/fs/kpy.ts +2 -2
  107. package/src/index.ts +0 -3
  108. package/src/jwt/jwt.service.ts +3 -2
  109. package/src/log/log.util.ts +1 -1
  110. package/src/script/runScript.ts +8 -8
  111. package/src/secret/secrets-decrypt.util.ts +1 -1
  112. package/src/secret/secrets-encrypt.util.ts +1 -1
  113. package/src/security/crypto.util.ts +1 -2
  114. package/src/security/hash.util.ts +1 -1
  115. package/src/security/secret.util.ts +3 -2
  116. package/src/slack/index.ts +2 -0
  117. package/src/slack/slack.service.model.ts +3 -2
  118. package/src/slack/slack.service.ts +11 -4
  119. package/src/stream/ndjson/ndjson.model.ts +2 -1
  120. package/src/stream/ndjson/ndjsonMap.ts +2 -2
  121. package/src/stream/ndjson/ndjsonStreamForEach.ts +8 -6
  122. package/src/stream/ndjson/transformJsonParse.ts +1 -1
  123. package/src/stream/ndjson/transformToNDJson.ts +1 -1
  124. package/src/stream/pipeline/pipeline.ts +4 -2
  125. package/src/stream/progressLogger.ts +5 -2
  126. package/src/stream/readable/readableForEach.ts +4 -4
  127. package/src/stream/readable/readableFromArray.ts +2 -2
  128. package/src/stream/sizeStack.ts +3 -2
  129. package/src/stream/stream.model.ts +1 -1
  130. package/src/stream/stream.util.ts +1 -1
  131. package/src/stream/transform/transformFilter.ts +1 -1
  132. package/src/stream/transform/transformLimit.ts +3 -2
  133. package/src/stream/transform/transformMap.ts +12 -15
  134. package/src/stream/transform/transformMapSimple.ts +3 -2
  135. package/src/stream/transform/transformMapSync.ts +4 -7
  136. package/src/stream/transform/transformOffset.ts +1 -1
  137. package/src/stream/transform/transformTap.ts +2 -1
  138. package/src/stream/transform/transformThrottle.ts +4 -3
  139. package/src/stream/transform/worker/transformMultiThreaded.ts +4 -2
  140. package/src/stream/writable/writableForEach.ts +4 -4
  141. package/src/stream/writable/writableFork.ts +3 -3
  142. package/src/stream/writable/writableVoid.ts +1 -1
  143. package/src/string/inspect.ts +2 -2
  144. package/src/util/buildInfo.util.ts +4 -2
  145. package/src/util/env.util.ts +1 -1
  146. package/src/util/git2.ts +2 -2
  147. package/src/validation/ajv/ajvSchema.ts +47 -39
  148. package/src/validation/ajv/ajvValidationError.ts +2 -2
  149. package/src/validation/ajv/getAjv.ts +12 -1
  150. package/src/validation/ajv/index.ts +0 -1
  151. package/src/validation/joi/joi.shared.schemas.ts +7 -7
  152. package/src/validation/joi/joi.validation.error.ts +2 -2
  153. package/src/validation/joi/joi.validation.util.ts +4 -1
  154. package/src/validation/joi/string.extensions.ts +2 -2
  155. package/dist/validation/ajv/ajv.util.d.ts +0 -21
  156. package/dist/validation/ajv/ajv.util.js +0 -28
  157. package/src/validation/ajv/ajv.util.ts +0 -38
@@ -1,5 +1,6 @@
1
1
  import { Transform } from 'node:stream';
2
- import { _ms, _since, localTime, pDefer } from '@naturalcycles/js-lib';
2
+ import { _ms, _since, localTime } from '@naturalcycles/js-lib/datetime';
3
+ import { pDefer } from '@naturalcycles/js-lib/promise';
3
4
  /**
4
5
  * Allows to throttle the throughput of the stream.
5
6
  * For example, when you have an API with rate limit of 5000 requests per minute,
@@ -1,4 +1,4 @@
1
- import type { AnyObject } from '@naturalcycles/js-lib';
1
+ import type { AnyObject } from '@naturalcycles/js-lib/types';
2
2
  import type { TransformTyped } from '../../stream.model.js';
3
3
  export interface TransformMultiThreadedOptions {
4
4
  /**
@@ -1,5 +1,6 @@
1
1
  import { Worker } from 'node:worker_threads';
2
- import { _range, pDefer } from '@naturalcycles/js-lib';
2
+ import { _range } from '@naturalcycles/js-lib';
3
+ import { pDefer } from '@naturalcycles/js-lib/promise';
3
4
  import through2Concurrent from 'through2-concurrent';
4
5
  const workerProxyFilePath = `${import.meta.dirname}/workerClassProxy.js`;
5
6
  /**
@@ -1,6 +1,6 @@
1
- import type { AsyncIndexedMapper, IndexedMapper } from '@naturalcycles/js-lib';
2
- import type { TransformMapOptions } from '../index.js';
1
+ import type { AsyncIndexedMapper, IndexedMapper } from '@naturalcycles/js-lib/types';
3
2
  import type { WritableTyped } from '../stream.model.js';
3
+ import { type TransformMapOptions } from '../transform/transformMap.js';
4
4
  /**
5
5
  * Just an alias to transformMap that declares OUT as void.
6
6
  */
@@ -1,5 +1,6 @@
1
- import { _passNothingPredicate } from '@naturalcycles/js-lib';
2
- import { transformMap, transformMapSync } from '../index.js';
1
+ import { _passNothingPredicate } from '@naturalcycles/js-lib/types';
2
+ import { transformMap } from '../transform/transformMap.js';
3
+ import { transformMapSync } from '../transform/transformMapSync.js';
3
4
  /**
4
5
  * Just an alias to transformMap that declares OUT as void.
5
6
  */
@@ -1,5 +1,6 @@
1
1
  import { Writable } from 'node:stream';
2
- import { _pipeline, readableCreate } from '../index.js';
2
+ import { _pipeline } from '../pipeline/pipeline.js';
3
+ import { readableCreate } from '../readable/readableCreate.js';
3
4
  /**
4
5
  * Allows "forking" a stream inside pipeline into a number of pipeline chains (2 or more).
5
6
  * Currently does NOT (!) maintain backpressure.
@@ -1,5 +1,5 @@
1
1
  import { Writable } from 'node:stream';
2
- import type { DeferredPromise } from '@naturalcycles/js-lib';
2
+ import type { DeferredPromise } from '@naturalcycles/js-lib/promise';
3
3
  import type { TransformOptions } from '../stream.model.js';
4
4
  export interface WritableVoidOptions extends TransformOptions {
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import type { InspectOptions } from 'node:util';
2
- import type { JsonStringifyFunction, StringifyOptions } from '@naturalcycles/js-lib';
2
+ import type { JsonStringifyFunction, StringifyOptions } from '@naturalcycles/js-lib/string';
3
3
  export interface InspectAnyOptions extends StringifyOptions, InspectOptions {
4
4
  }
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { inspect } from 'node:util';
2
- import { _stringify } from '@naturalcycles/js-lib';
2
+ import { _stringify } from '@naturalcycles/js-lib/string';
3
3
  const INSPECT_OPT = {
4
4
  breakLength: 80, // default: ??
5
5
  depth: 10, // default: 2
@@ -1,4 +1,5 @@
1
- import type { BuildInfo, UnixTimestamp } from '@naturalcycles/js-lib';
1
+ import type { BuildInfo } from '@naturalcycles/js-lib';
2
+ import type { UnixTimestamp } from '@naturalcycles/js-lib/types';
2
3
  export interface GenerateBuildInfoOptions {
3
4
  /**
4
5
  * If set - this timestamp will be used, instead of "current time".
@@ -1,4 +1,5 @@
1
- import { _filterUndefinedValues, localTime } from '@naturalcycles/js-lib';
1
+ import { localTime } from '@naturalcycles/js-lib/datetime';
2
+ import { _filterUndefinedValues } from '@naturalcycles/js-lib/object';
2
3
  import { fs2 } from '../fs/fs2.js';
3
4
  import { git2 } from './git2.js';
4
5
  export function generateBuildInfo(opt = {}) {
@@ -1,4 +1,4 @@
1
- import type { ValuesOf } from '@naturalcycles/js-lib';
1
+ import type { ValuesOf } from '@naturalcycles/js-lib/types';
2
2
  /**
3
3
  * @example
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { UnixTimestamp } from '@naturalcycles/js-lib';
1
+ import type { UnixTimestamp } from '@naturalcycles/js-lib/types';
2
2
  /**
3
3
  * Set of utility functions to work with git.
4
4
  */
package/dist/util/git2.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { execSync } from 'node:child_process';
2
2
  import { basename } from 'node:path';
3
- import { exec2 } from '../exec2.js';
3
+ import { exec2 } from '../exec2/exec2.js';
4
4
  /**
5
5
  * Set of utility functions to work with git.
6
6
  */
@@ -1,4 +1,4 @@
1
- import type { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib';
1
+ import type { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib/json-schema';
2
2
  import type { Ajv } from 'ajv';
3
3
  import { AjvValidationError } from './ajvValidationError.js';
4
4
  export interface AjvValidationOptions {
@@ -15,7 +15,6 @@ export interface AjvSchemaCfg {
15
15
  * Dependent schemas to pass to Ajv instance constructor.
16
16
  * Simpler than instantiating and passing ajv instance yourself.
17
17
  */
18
- schemas?: (JsonSchema | JsonSchemaBuilder | AjvSchema)[];
19
18
  objectName?: string;
20
19
  /**
21
20
  * Option of Ajv.
@@ -24,7 +23,11 @@ export interface AjvSchemaCfg {
24
23
  *
25
24
  * This option is a "shortcut" to skip creating and passing Ajv instance.
26
25
  */
27
- coerceTypes?: boolean;
26
+ /**
27
+ * If true - schema will be compiled on-demand (lazily).
28
+ * Default: false.
29
+ */
30
+ lazy?: boolean;
28
31
  }
29
32
  /**
30
33
  * On creation - compiles ajv validation function.
@@ -35,6 +38,10 @@ export interface AjvSchemaCfg {
35
38
  export declare class AjvSchema<T = unknown> {
36
39
  schema: JsonSchema<T>;
37
40
  private constructor();
41
+ /**
42
+ * Shortcut for AjvSchema.create(schema, { lazy: true })
43
+ */
44
+ static createLazy<T>(schema: JsonSchemaBuilder<T> | JsonSchema<T> | AjvSchema<T>, cfg?: Partial<AjvSchemaCfg>): AjvSchema<T>;
38
45
  /**
39
46
  * Conveniently allows to pass either JsonSchema or JsonSchemaBuilder, or existing AjvSchema.
40
47
  * If it's already an AjvSchema - it'll just return it without any processing.
@@ -45,13 +52,8 @@ export declare class AjvSchema<T = unknown> {
45
52
  * correctly for some reason.
46
53
  */
47
54
  static create<T>(schema: JsonSchemaBuilder<T> | JsonSchema<T> | AjvSchema<T>, cfg?: Partial<AjvSchemaCfg>): AjvSchema<T>;
48
- /**
49
- * Create AjvSchema directly from a filePath of json schema.
50
- * Convenient method that just does fs.readFileSync for you.
51
- */
52
- static readJsonSync<T = unknown>(filePath: string, cfg?: Partial<AjvSchemaCfg>): AjvSchema<T>;
53
55
  readonly cfg: AjvSchemaCfg;
54
- private readonly validateFunction;
56
+ private getValidateFunction;
55
57
  /**
56
58
  * It returns the original object just for convenience.
57
59
  * Reminder: Ajv will MUTATE your object under 2 circumstances:
@@ -1,5 +1,7 @@
1
- import { _filterNullishValues, _isObject, _substringBefore, JsonSchemaAnyBuilder, } from '@naturalcycles/js-lib';
2
- import { fs2 } from '../../fs/fs2.js';
1
+ import { _isObject, _lazyValue } from '@naturalcycles/js-lib';
2
+ import { JsonSchemaAnyBuilder } from '@naturalcycles/js-lib/json-schema';
3
+ import { _filterNullishValues } from '@naturalcycles/js-lib/object';
4
+ import { _substringBefore } from '@naturalcycles/js-lib/string';
3
5
  import { _inspect } from '../../string/inspect.js';
4
6
  import { AjvValidationError } from './ajvValidationError.js';
5
7
  import { getAjv } from './getAjv.js';
@@ -14,23 +16,35 @@ export class AjvSchema {
14
16
  constructor(schema, cfg = {}) {
15
17
  this.schema = schema;
16
18
  this.cfg = {
19
+ lazy: false,
17
20
  ...cfg,
18
- ajv: cfg.ajv ||
19
- getAjv({
20
- schemas: cfg.schemas?.map(s => {
21
- if (s instanceof AjvSchema)
22
- return s.schema;
23
- if (s instanceof JsonSchemaAnyBuilder)
24
- return s.build();
25
- return s;
26
- }),
27
- coerceTypes: cfg.coerceTypes || false,
28
- // verbose: true,
29
- }),
21
+ ajv: cfg.ajv || getAjv(),
22
+ // ajv:
23
+ // cfg.ajv ||
24
+ // getAjv({
25
+ // schemas: cfg.schemas?.map(s => {
26
+ // if (s instanceof AjvSchema) return s.schema
27
+ // if (s instanceof JsonSchemaAnyBuilder) return s.build()
28
+ // return s as JsonSchema
29
+ // }),
30
+ // coerceTypes: cfg.coerceTypes || false,
31
+ // // verbose: true,
32
+ // }),
30
33
  // Auto-detecting "ObjectName" from $id of the schema (e.g "Address.schema.json")
31
34
  objectName: cfg.objectName || (schema.$id ? _substringBefore(schema.$id, '.') : undefined),
32
35
  };
33
- this.validateFunction = this.cfg.ajv.compile(schema);
36
+ if (!cfg.lazy) {
37
+ this.getValidateFunction(); // compile eagerly
38
+ }
39
+ }
40
+ /**
41
+ * Shortcut for AjvSchema.create(schema, { lazy: true })
42
+ */
43
+ static createLazy(schema, cfg = {}) {
44
+ return AjvSchema.create(schema, {
45
+ lazy: true,
46
+ ...cfg,
47
+ });
34
48
  }
35
49
  /**
36
50
  * Conveniently allows to pass either JsonSchema or JsonSchemaBuilder, or existing AjvSchema.
@@ -49,17 +63,8 @@ export class AjvSchema {
49
63
  }
50
64
  return new AjvSchema(schema, cfg);
51
65
  }
52
- /**
53
- * Create AjvSchema directly from a filePath of json schema.
54
- * Convenient method that just does fs.readFileSync for you.
55
- */
56
- static readJsonSync(filePath, cfg = {}) {
57
- fs2.requireFileToExist(filePath);
58
- const schema = fs2.readJson(filePath);
59
- return new AjvSchema(schema, cfg);
60
- }
61
66
  cfg;
62
- validateFunction;
67
+ getValidateFunction = _lazyValue(() => this.cfg.ajv.compile(this.schema));
63
68
  /**
64
69
  * It returns the original object just for convenience.
65
70
  * Reminder: Ajv will MUTATE your object under 2 circumstances:
@@ -75,12 +80,12 @@ export class AjvSchema {
75
80
  return obj;
76
81
  }
77
82
  isValid(obj) {
78
- return this.validateFunction(obj);
83
+ return this.getValidateFunction()(obj);
79
84
  }
80
85
  getValidationError(obj, opt = {}) {
81
86
  if (this.isValid(obj))
82
87
  return;
83
- const errors = this.validateFunction.errors;
88
+ const errors = this.getValidateFunction().errors;
84
89
  const { objectId = _isObject(obj) ? obj['id'] : undefined, objectName = this.cfg.objectName, } = opt;
85
90
  const name = [objectName || 'Object', objectId].filter(Boolean).join('.');
86
91
  let message = this.cfg.ajv.errorsText(errors, {
@@ -1,5 +1,5 @@
1
- import type { ErrorData } from '@naturalcycles/js-lib';
2
- import { AppError } from '@naturalcycles/js-lib';
1
+ import type { ErrorData } from '@naturalcycles/js-lib/error';
2
+ import { AppError } from '@naturalcycles/js-lib/error';
3
3
  import type { ErrorObject } from 'ajv';
4
4
  export interface AjvValidationErrorData extends ErrorData {
5
5
  errors: ErrorObject[];
@@ -1,4 +1,4 @@
1
- import { AppError } from '@naturalcycles/js-lib';
1
+ import { AppError } from '@naturalcycles/js-lib/error';
2
2
  export class AjvValidationError extends AppError {
3
3
  constructor(message, data) {
4
4
  super(message, data, {
@@ -1,8 +1,17 @@
1
1
  import type { Options } from 'ajv';
2
2
  import { Ajv } from 'ajv';
3
+ /**
4
+ * Return cached instance of Ajv with default (recommended) options.
5
+ *
6
+ * This function should be used as much as possible,
7
+ * to benefit from cached Ajv instance.
8
+ */
9
+ export declare const getAjv: import("@naturalcycles/js-lib/types").Lazy<Ajv>;
3
10
  /**
4
11
  * Create Ajv with modified defaults.
5
12
  *
13
+ * !!! Please note that this function is EXPENSIVE computationally !!!
14
+ *
6
15
  * https://ajv.js.org/options.html
7
16
  */
8
- export declare function getAjv(opt?: Options): Ajv;
17
+ export declare function createAjv(opt?: Options): Ajv;
@@ -1,3 +1,4 @@
1
+ import { _lazyValue } from '@naturalcycles/js-lib';
1
2
  import { Ajv } from 'ajv';
2
3
  import ajvFormats from 'ajv-formats';
3
4
  import ajvKeywords from 'ajv-keywords';
@@ -10,12 +11,21 @@ const AJV_OPTIONS = {
10
11
  // https://ajv.js.org/options.html#coercetypes
11
12
  coerceTypes: false, // while `false` - it won't mutate your input
12
13
  };
14
+ /**
15
+ * Return cached instance of Ajv with default (recommended) options.
16
+ *
17
+ * This function should be used as much as possible,
18
+ * to benefit from cached Ajv instance.
19
+ */
20
+ export const getAjv = _lazyValue(createAjv);
13
21
  /**
14
22
  * Create Ajv with modified defaults.
15
23
  *
24
+ * !!! Please note that this function is EXPENSIVE computationally !!!
25
+ *
16
26
  * https://ajv.js.org/options.html
17
27
  */
18
- export function getAjv(opt) {
28
+ export function createAjv(opt) {
19
29
  const ajv = new Ajv({
20
30
  ...AJV_OPTIONS,
21
31
  ...opt,
@@ -1,5 +1,4 @@
1
1
  import Ajv from 'ajv';
2
- export * from './ajv.util.js';
3
2
  export * from './ajvSchema.js';
4
3
  export * from './ajvValidationError.js';
5
4
  export * from './getAjv.js';
@@ -1,5 +1,4 @@
1
1
  import Ajv from 'ajv';
2
- export * from './ajv.util.js';
3
2
  export * from './ajvSchema.js';
4
3
  export * from './ajvValidationError.js';
5
4
  export * from './getAjv.js';
@@ -1,4 +1,4 @@
1
- import type { BaseDBEntity, IANATimezone, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib';
1
+ import type { BaseDBEntity, IANATimezone, IsoDateTime, NumberEnum, StringEnum, UnixTimestamp, UnixTimestampMillis } from '@naturalcycles/js-lib/types';
2
2
  import type { AlternativesSchema, AnySchema, ArraySchema, ObjectSchema } from 'joi';
3
3
  import type { NumberSchema } from './number.extensions.js';
4
4
  import type { StringSchema } from './string.extensions.js';
@@ -10,7 +10,7 @@ export declare const numberSchema: NumberSchema<number>;
10
10
  export declare const numberSchemaTyped: <T>() => NumberSchema<T>;
11
11
  export declare const integerSchema: NumberSchema<number>;
12
12
  export declare const percentageSchema: NumberSchema<number>;
13
- export declare const dateStringSchema: StringSchema<import("@naturalcycles/js-lib").IsoDate>;
13
+ export declare const dateStringSchema: StringSchema<import("@naturalcycles/js-lib/types").IsoDate>;
14
14
  export declare const binarySchema: import("joi").BinarySchema<Buffer<ArrayBufferLike>>;
15
15
  export declare const dateObjectSchema: ObjectSchema<any>;
16
16
  export declare const dateIntervalStringSchema: StringSchema<string>;
@@ -1,5 +1,5 @@
1
- import type { ErrorData } from '@naturalcycles/js-lib';
2
- import { AppError } from '@naturalcycles/js-lib';
1
+ import type { ErrorData } from '@naturalcycles/js-lib/error';
2
+ import { AppError } from '@naturalcycles/js-lib/error';
3
3
  import type { ValidationErrorItem } from 'joi';
4
4
  /**
5
5
  * Example of ValidationErrorItem:
@@ -1,4 +1,4 @@
1
- import { AppError } from '@naturalcycles/js-lib';
1
+ import { AppError } from '@naturalcycles/js-lib/error';
2
2
  export class JoiValidationError extends AppError {
3
3
  constructor(message, data) {
4
4
  super(message, data, {
@@ -17,6 +17,8 @@ export declare function validate<T>(input: any, schema?: AnySchema<T>, objectNam
17
17
  * Returns JoiValidationResult with converted value and error (if any).
18
18
  * Does not throw.
19
19
  *
20
+ * Joi does NOT mutate the input.
21
+ *
20
22
  * If `schema` is undefined - returns value as is.
21
23
  */
22
24
  export declare function getValidationResult<T>(input: any, schema?: AnySchema<T>, objectName?: string, options?: ValidationOptions): JoiValidationResult<T>;
@@ -5,7 +5,8 @@
5
5
  *
6
6
  * "Converts" mean e.g trims all strings from leading/trailing spaces.
7
7
  */
8
- import { _hb, _isObject, _truncateMiddle } from '@naturalcycles/js-lib';
8
+ import { _hb, _isObject } from '@naturalcycles/js-lib';
9
+ import { _truncateMiddle } from '@naturalcycles/js-lib/string';
9
10
  import { JoiValidationError } from './joi.validation.error.js';
10
11
  // Strip colors in production (for e.g Sentry reporting)
11
12
  // const stripColors = process.env.NODE_ENV === 'production' || !!process.env.GAE_INSTANCE
@@ -49,6 +50,8 @@ export function validate(input, schema, objectName, opt = {}) {
49
50
  * Returns JoiValidationResult with converted value and error (if any).
50
51
  * Does not throw.
51
52
  *
53
+ * Joi does NOT mutate the input.
54
+ *
52
55
  * If `schema` is undefined - returns value as is.
53
56
  */
54
57
  export function getValidationResult(input, schema, objectName, options = {}) {
@@ -1,4 +1,4 @@
1
- import type { IsoDate } from '@naturalcycles/js-lib';
1
+ import type { IsoDate } from '@naturalcycles/js-lib/types';
2
2
  import type Joi from 'joi';
3
3
  import type { Extension, StringSchema as JoiStringSchema } from 'joi';
4
4
  export interface StringSchema<TSchema = string> extends JoiStringSchema<TSchema> {
@@ -1,4 +1,4 @@
1
- import { localTime } from '@naturalcycles/js-lib';
1
+ import { localTime } from '@naturalcycles/js-lib/datetime';
2
2
  export function stringExtensions(joi) {
3
3
  return {
4
4
  type: 'string',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.2.0",
4
+ "version": "15.4.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@types/js-yaml": "^4",
@@ -30,14 +30,17 @@
30
30
  "./lruMemoCache": "./dist/cache/lruMemoCache.js",
31
31
  "./colors": "./dist/colors/colors.js",
32
32
  "./csv": "./dist/csv/index.js",
33
- "./exec2": "./dist/exec2.js",
33
+ "./exec2": "./dist/exec2/exec2.js",
34
34
  "./fs2": "./dist/fs/fs2.js",
35
35
  "./env": "./dist/fs/json2env.js",
36
36
  "./kpy": "./dist/fs/kpy.js",
37
37
  "./yaml2": "./dist/fs/yaml2.js",
38
38
  "./glob": "./dist/glob/index.js",
39
39
  "./jwt": "./dist/jwt/jwt.service.js",
40
+ "./runScript": "./dist/script/runScript.js",
41
+ "./slack": "./dist/slack/index.js",
40
42
  "./stream": "./dist/stream/index.js",
43
+ "./stream/*.js": "./dist/stream/*.js",
41
44
  "./yargs": "./dist/yargs/yargs.util.js",
42
45
  "./ajv": "./dist/validation/ajv/index.js",
43
46
  "./joi": "./dist/validation/joi/index.js",
@@ -60,7 +63,6 @@
60
63
  "!src/**/__snapshots__",
61
64
  "!src/**/__exclude"
62
65
  ],
63
- "main": "dist/index.js",
64
66
  "types": "dist/index.d.ts",
65
67
  "publishConfig": {
66
68
  "access": "public"
@@ -2,7 +2,7 @@
2
2
 
3
3
  import fs from 'node:fs'
4
4
  import path from 'node:path'
5
- import type { UnixTimestamp } from '@naturalcycles/js-lib'
5
+ import type { UnixTimestamp } from '@naturalcycles/js-lib/types'
6
6
  import { appendToBashEnv, appendToGithubEnv, appendToGithubOutput } from '../fs/json2env.js'
7
7
  import { runScript } from '../script/runScript.js'
8
8
  import { generateBuildInfo } from '../util/buildInfo.util.js'
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { SlackService } from '../index.js'
4
3
  import { runScript } from '../script/runScript.js'
4
+ import { SlackService } from '../slack/index.js'
5
5
  import { _yargs } from '../yargs/yargs.util.js'
6
6
 
7
7
  runScript(async () => {
@@ -1,4 +1,4 @@
1
- import type { MemoCache } from '@naturalcycles/js-lib'
1
+ import type { MemoCache } from '@naturalcycles/js-lib/decorators'
2
2
  import { LRUCache } from 'lru-cache'
3
3
 
4
4
  // Partial, to be able to provide default `max`
@@ -1,7 +1,7 @@
1
1
  // Inspired by: https://gist.github.com/Jezternz/c8e9fafc2c114e079829974e3764db75
2
2
 
3
- import type { AnyObject } from '@naturalcycles/js-lib'
4
- import { _assert } from '@naturalcycles/js-lib'
3
+ import { _assert } from '@naturalcycles/js-lib/error'
4
+ import type { AnyObject } from '@naturalcycles/js-lib/types'
5
5
 
6
6
  export interface CSVReaderConfig {
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  // Inspired by: https://github.com/ryu1kn/csv-writer/
2
2
 
3
- import type { AnyObject } from '@naturalcycles/js-lib'
4
- import { _assert } from '@naturalcycles/js-lib'
3
+ import { _assert } from '@naturalcycles/js-lib/error'
4
+ import type { AnyObject } from '@naturalcycles/js-lib/types'
5
5
 
6
6
  export interface CSVWriterConfig {
7
7
  /**
@@ -1,5 +1,5 @@
1
1
  import { Transform } from 'node:stream'
2
- import type { AnyObject } from '@naturalcycles/js-lib'
2
+ import type { AnyObject } from '@naturalcycles/js-lib/types'
3
3
  import type { TransformTyped } from '../stream/stream.model.js'
4
4
  import type { CSVWriterConfig } from './csvWriter.js'
5
5
  import { CSVWriter } from './csvWriter.js'
@@ -1,5 +1,5 @@
1
- import type { AnyObject } from '@naturalcycles/js-lib'
2
- import { _truncate } from '@naturalcycles/js-lib'
1
+ import { _truncate } from '@naturalcycles/js-lib/string'
2
+ import type { AnyObject } from '@naturalcycles/js-lib/types'
3
3
 
4
4
  export interface TableDiffOptions {
5
5
  /**
@@ -1,12 +1,13 @@
1
1
  import { execSync, spawn, spawnSync } from 'node:child_process'
2
- import {
3
- _substringAfterLast,
4
- type AnyObject,
5
- type NumberOfMilliseconds,
6
- type UnixTimestampMillis,
7
- } from '@naturalcycles/js-lib'
8
- import { _since, AppError } from '@naturalcycles/js-lib'
9
- import { dimGrey, dimRed, hasColors, white } from './colors/colors.js'
2
+ import { _since } from '@naturalcycles/js-lib/datetime'
3
+ import { AppError } from '@naturalcycles/js-lib/error'
4
+ import { _substringAfterLast } from '@naturalcycles/js-lib/string'
5
+ import type {
6
+ AnyObject,
7
+ NumberOfMilliseconds,
8
+ UnixTimestampMillis,
9
+ } from '@naturalcycles/js-lib/types'
10
+ import { dimGrey, dimRed, hasColors, white } from '../colors/colors.js'
10
11
 
11
12
  /**
12
13
  * Set of utility functions to work with Spawn / Exec.
package/src/fs/fs2.ts CHANGED
@@ -18,7 +18,7 @@ import type { RmOptions, Stats } from 'node:fs'
18
18
  import fs from 'node:fs'
19
19
  import fsp from 'node:fs/promises'
20
20
  import path from 'node:path'
21
- import { _jsonParse } from '@naturalcycles/js-lib'
21
+ import { _jsonParse } from '@naturalcycles/js-lib/string'
22
22
 
23
23
  /**
24
24
  * fs2 conveniently groups filesystem functions together.
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs'
2
- import type { AnyObject } from '@naturalcycles/js-lib'
2
+ import type { AnyObject } from '@naturalcycles/js-lib/types'
3
3
  import { dimGrey } from '../colors/colors.js'
4
4
  import { fs2 } from './fs2.js'
5
5
 
package/src/fs/kpy.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path'
2
- import type { UnixTimestampMillis } from '@naturalcycles/js-lib'
3
- import { _since, localTime } from '@naturalcycles/js-lib'
2
+ import { _since, localTime } from '@naturalcycles/js-lib/datetime'
3
+ import type { UnixTimestampMillis } from '@naturalcycles/js-lib/types'
4
4
  import { glob, globSync } from 'tinyglobby'
5
5
  import { boldWhite, dimGrey, grey, yellow } from '../colors/colors.js'
6
6
  import { fs2 } from './fs2.js'
package/src/index.ts CHANGED
@@ -2,14 +2,11 @@ export * from './buffer/buffer.util.js'
2
2
  export * from './diff/tableDiff.js'
3
3
  export * from './infra/process.util.js'
4
4
  export * from './log/log.util.js'
5
- export * from './script/runScript.js'
6
5
  export * from './security/crypto.util.js'
7
6
  export * from './security/hash.util.js'
8
7
  export * from './security/id.util.js'
9
8
  export * from './security/nanoid.js'
10
9
  export * from './security/secret.util.js'
11
- export * from './slack/slack.service.js'
12
- export * from './slack/slack.service.model.js'
13
10
  export * from './string/inspect.js'
14
11
  export * from './util/buildInfo.util.js'
15
12
  export * from './util/env.util.js'
@@ -1,5 +1,6 @@
1
- import type { AnyObject, ErrorData, JWTString } from '@naturalcycles/js-lib'
2
- import { _assert, _errorDataAppend } from '@naturalcycles/js-lib'
1
+ import type { ErrorData } from '@naturalcycles/js-lib/error'
2
+ import { _assert, _errorDataAppend } from '@naturalcycles/js-lib/error'
3
+ import type { AnyObject, JWTString } from '@naturalcycles/js-lib/types'
3
4
  import type { AnySchema } from 'joi'
4
5
  import type { Algorithm, JwtHeader, SignOptions, VerifyOptions } from 'jsonwebtoken'
5
6
  import jsonwebtoken from 'jsonwebtoken'
@@ -1,4 +1,4 @@
1
- import { commonLoggerCreate } from '@naturalcycles/js-lib'
1
+ import { commonLoggerCreate } from '@naturalcycles/js-lib/log'
2
2
  import { _inspect } from '../string/inspect.js'
3
3
 
4
4
  /**