@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,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { SlackService } from '../index.js';
3
2
  import { runScript } from '../script/runScript.js';
3
+ import { SlackService } from '../slack/index.js';
4
4
  import { _yargs } from '../yargs/yargs.util.js';
5
5
  runScript(async () => {
6
6
  const { channel, msg, username, emoji, webhook: webhookUrl, } = _yargs().options({
@@ -1,5 +1,5 @@
1
1
  // Inspired by: https://gist.github.com/Jezternz/c8e9fafc2c114e079829974e3764db75
2
- import { _assert } from '@naturalcycles/js-lib/error';
2
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
3
3
  // export class CSVReader {
4
4
  // constructor (cfg: CSVReaderConfig) {
5
5
  // this.cfg = {
@@ -1,5 +1,5 @@
1
1
  // Inspired by: https://github.com/ryu1kn/csv-writer/
2
- import { _assert } from '@naturalcycles/js-lib/error';
2
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
3
3
  export class CSVWriter {
4
4
  constructor(cfg) {
5
5
  this.cfg = {
@@ -1,4 +1,4 @@
1
- import { _truncate } from '@naturalcycles/js-lib/string';
1
+ import { _truncate } from '@naturalcycles/js-lib/string/string.util.js';
2
2
  /**
3
3
  * Compares 2 objects, logs their differences via `console.table`.
4
4
  *
@@ -1,4 +1,4 @@
1
- import { AppError } from '@naturalcycles/js-lib/error';
1
+ import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
2
2
  import type { AnyObject, NumberOfMilliseconds } from '@naturalcycles/js-lib/types';
3
3
  /**
4
4
  * Set of utility functions to work with Spawn / Exec.
@@ -1,8 +1,8 @@
1
1
  import { execSync, spawn, spawnSync } from 'node:child_process';
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 { dimGrey, dimRed, hasColors, white } from './colors/colors.js';
2
+ import { _since } from '@naturalcycles/js-lib/datetime/time.util.js';
3
+ import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
4
+ import { _substringAfterLast } from '@naturalcycles/js-lib/string/string.util.js';
5
+ import { dimGrey, dimRed, hasColors, white } from '../colors/colors.js';
6
6
  /**
7
7
  * Set of utility functions to work with Spawn / Exec.
8
8
  *
package/dist/fs/fs2.js CHANGED
@@ -16,7 +16,7 @@ Credit to: fs-extra (https://github.com/jprichardson/node-fs-extra)
16
16
  import fs from 'node:fs';
17
17
  import fsp from 'node:fs/promises';
18
18
  import path from 'node:path';
19
- import { _jsonParse } from '@naturalcycles/js-lib/string';
19
+ import { _jsonParse } from '@naturalcycles/js-lib/string/json.util.js';
20
20
  /**
21
21
  * fs2 conveniently groups filesystem functions together.
22
22
  * Supposed to be almost a drop-in replacement for these things together:
package/dist/index.d.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';
package/dist/index.js 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,4 +1,5 @@
1
- import { _assert, _errorDataAppend } from '@naturalcycles/js-lib/error';
1
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
2
+ import { _errorDataAppend } from '@naturalcycles/js-lib/error/error.util.js';
2
3
  import jsonwebtoken from 'jsonwebtoken';
3
4
  import { anyObjectSchema } from '../validation/joi/joi.shared.schemas.js';
4
5
  import { validate } from '../validation/joi/joi.validation.util.js';
@@ -1,3 +1,4 @@
1
+ import 'dotenv/config';
1
2
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
2
3
  export interface RunScriptOptions {
3
4
  /**
@@ -1,6 +1,8 @@
1
+ import 'dotenv/config';
1
2
  import os from 'node:os';
2
- import { pDelay } from '@naturalcycles/js-lib/promise';
3
- import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string';
3
+ import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js';
4
+ import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string/stringify.js';
5
+ import { dimGrey } from '../colors/colors.js';
4
6
  import { inspectStringifyFn } from '../string/inspect.js';
5
7
  const { DEBUG_RUN_SCRIPT } = process.env;
6
8
  /**
@@ -22,6 +24,7 @@ const { DEBUG_RUN_SCRIPT } = process.env;
22
24
  * Set env DEBUG_RUN_SCRIPT for extra debugging.
23
25
  */
24
26
  export function runScript(fn, opt = {}) {
27
+ checkAndlogEnvironment();
25
28
  setGlobalStringifyFunction(inspectStringifyFn);
26
29
  const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt;
27
30
  if (registerUncaughtExceptionHandlers || DEBUG_RUN_SCRIPT) {
@@ -40,8 +43,6 @@ export function runScript(fn, opt = {}) {
40
43
  const timeout = setTimeout(() => { }, 10000000);
41
44
  void (async () => {
42
45
  try {
43
- await import('dotenv/config');
44
- await checkAndlogEnvironment();
45
46
  await fn();
46
47
  await pDelay(); // to ensure all async operations are completed
47
48
  if (DEBUG_RUN_SCRIPT)
@@ -62,8 +63,7 @@ export function runScript(fn, opt = {}) {
62
63
  }
63
64
  })();
64
65
  }
65
- async function checkAndlogEnvironment() {
66
- const { dimGrey } = await import('../colors/colors.js');
66
+ function checkAndlogEnvironment() {
67
67
  const { platform, arch, versions: { node }, env: { CPU_LIMIT, NODE_OPTIONS, TZ }, } = process;
68
68
  const cpuLimit = Number(CPU_LIMIT) || undefined;
69
69
  const availableParallelism = os.availableParallelism?.();
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { _assert } from '@naturalcycles/js-lib/error';
3
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
4
4
  import { globSync } from 'tinyglobby';
5
5
  import { dimGrey, yellow } from '../colors/colors.js';
6
6
  import { fs2 } from '../fs/fs2.js';
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { _assert } from '@naturalcycles/js-lib/error';
3
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
4
4
  import { globSync } from 'tinyglobby';
5
5
  import { dimGrey, yellow } from '../colors/colors.js';
6
6
  import { fs2 } from '../fs/fs2.js';
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
- import { _assert } from '@naturalcycles/js-lib/error';
3
- import { _jsonParseIfPossible } from '@naturalcycles/js-lib/string';
2
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
3
+ import { _jsonParseIfPossible } from '@naturalcycles/js-lib/string/json.util.js';
4
4
  import { decryptObject, decryptRandomIVBuffer } from './crypto.util.js';
5
5
  let loaded = false;
6
6
  const secretMap = {};
@@ -0,0 +1,2 @@
1
+ export * from './slack.service.js';
2
+ export * from './slack.service.model.js';
@@ -0,0 +1,2 @@
1
+ export * from './slack.service.js';
2
+ export * from './slack.service.model.js';
@@ -1,8 +1,8 @@
1
- import { localTime } from '@naturalcycles/js-lib/datetime';
1
+ import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
2
2
  import { getFetcher } from '@naturalcycles/js-lib/http';
3
3
  import { commonLoggerMinLevel, } from '@naturalcycles/js-lib/log';
4
- import { _omit } from '@naturalcycles/js-lib/object';
5
- import { PQueue } from '@naturalcycles/js-lib/promise';
4
+ import { _omit } from '@naturalcycles/js-lib/object/object.util.js';
5
+ import { PQueue } from '@naturalcycles/js-lib/promise/pQueue.js';
6
6
  import { _inspect } from '../index.js';
7
7
  const GAE = !!process.env['GAE_INSTANCE'];
8
8
  const DEFAULTS = {
@@ -1,6 +1,6 @@
1
1
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
2
2
  import type { AnyObject } from '@naturalcycles/js-lib/types';
3
- import type { InspectAnyOptions } from '../index.js';
3
+ import type { InspectAnyOptions } from '../string/inspect.js';
4
4
  /**
5
5
  * Properties that exists both in SlackApiBody (as per Slack API) and SlackMessage (our abstraction).
6
6
  */
@@ -1,5 +1,5 @@
1
1
  import { _hb } from '@naturalcycles/js-lib';
2
- import { _ms } from '@naturalcycles/js-lib/datetime';
2
+ import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
3
3
  import { boldWhite, dimWhite } from '../../colors/colors.js';
4
4
  export class NDJsonStats {
5
5
  static create(o = {}) {
@@ -1,4 +1,4 @@
1
- import { ErrorMode } from '@naturalcycles/js-lib/error';
1
+ import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js';
2
2
  import { createReadStreamAsNDJSON, createWriteStreamAsNDJSON, } from '../index.js';
3
3
  import { _pipeline, transformLimit, transformLogProgress, transformMap } from '../index.js';
4
4
  /**
@@ -1,5 +1,6 @@
1
1
  import type { AbortableAsyncMapper } from '@naturalcycles/js-lib/types';
2
- import { type TransformLogProgressOptions, type TransformMapOptions } from '../index.js';
2
+ import { type TransformLogProgressOptions } from '../transform/transformLogProgress.js';
3
+ import { type TransformMapOptions } from '../transform/transformMap.js';
3
4
  export interface NDJSONStreamForEachOptions<IN = any> extends TransformMapOptions<IN, void>, TransformLogProgressOptions<IN> {
4
5
  inputFilePath: string;
5
6
  }
@@ -1,6 +1,9 @@
1
- import { ErrorMode } from '@naturalcycles/js-lib/error';
2
- import { createReadStreamAsNDJSON, } from '../index.js';
3
- import { _pipeline, transformLogProgress, transformMap, writableVoid } from '../index.js';
1
+ import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js';
2
+ import { _pipeline } from '../pipeline/pipeline.js';
3
+ import { transformLogProgress, } from '../transform/transformLogProgress.js';
4
+ import { transformMap } from '../transform/transformMap.js';
5
+ import { writableVoid } from '../writable/writableVoid.js';
6
+ import { createReadStreamAsNDJSON } from './createReadStreamAsNDJSON.js';
4
7
  /**
5
8
  * Convenience function to `forEach` through an ndjson file.
6
9
  */
@@ -1,7 +1,7 @@
1
1
  import { Transform } from 'node:stream';
2
2
  import { pipeline } from 'node:stream/promises';
3
- import { _last } from '@naturalcycles/js-lib';
4
- import { pDefer } from '@naturalcycles/js-lib/promise';
3
+ import { _last } from '@naturalcycles/js-lib/array/array.util.js';
4
+ import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js';
5
5
  import { writablePushToArray } from '../writable/writablePushToArray.js';
6
6
  /**
7
7
  * Promisified `stream.pipeline`.
@@ -1,5 +1,5 @@
1
1
  import type { AbortableAsyncMapper, IndexedMapper } from '@naturalcycles/js-lib/types';
2
- import type { ReadableTyped } from '../index.js';
2
+ import type { ReadableTyped } from '../stream.model.js';
3
3
  import type { TransformMapOptions } from '../transform/transformMap.js';
4
4
  /**
5
5
  * Convenience function to do `.forEach` over a Readable.
@@ -1,5 +1,5 @@
1
1
  import { _passNothingPredicate } from '@naturalcycles/js-lib/types';
2
- import { _pipeline } from '../index.js';
2
+ import { _pipeline } from '../pipeline/pipeline.js';
3
3
  import { transformMap } from '../transform/transformMap.js';
4
4
  /**
5
5
  * Convenience function to do `.forEach` over a Readable.
@@ -1,5 +1,5 @@
1
1
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
2
- import { NumberStack } from '@naturalcycles/js-lib/math';
2
+ import { NumberStack } from '@naturalcycles/js-lib/math/stack.util.js';
3
3
  export declare class SizeStack extends NumberStack {
4
4
  name: string;
5
5
  constructor(name: string, size: number);
@@ -1,5 +1,5 @@
1
1
  import { _hb } from '@naturalcycles/js-lib';
2
- import { NumberStack } from '@naturalcycles/js-lib/math';
2
+ import { NumberStack } from '@naturalcycles/js-lib/math/stack.util.js';
3
3
  import { yellow } from '../colors/colors.js';
4
4
  import { gzipBuffer } from '../zip/zip.util.js';
5
5
  export class SizeStack extends NumberStack {
@@ -1,6 +1,6 @@
1
1
  import type { Readable } from 'node:stream';
2
2
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
3
- import { AbortableTransform } from '../index.js';
3
+ import { AbortableTransform } from '../pipeline/pipeline.js';
4
4
  import type { TransformOptions, TransformTyped } from '../stream.model.js';
5
5
  export interface TransformLimitOptions extends TransformOptions {
6
6
  /**
@@ -1,5 +1,6 @@
1
- import { AbortableTransform, transformNoOp } from '../index.js';
1
+ import { AbortableTransform } from '../pipeline/pipeline.js';
2
2
  import { pipelineClose } from '../stream.util.js';
3
+ import { transformNoOp } from './transformNoOp.js';
3
4
  /**
4
5
  * Class only exists to be able to do `instanceof TransformLimit`
5
6
  * and to set sourceReadable+streamDone to it in `_pipeline`.
@@ -1,8 +1,8 @@
1
1
  import { _hc } from '@naturalcycles/js-lib';
2
- import { _since } from '@naturalcycles/js-lib/datetime';
2
+ import { _since } from '@naturalcycles/js-lib/datetime/time.util.js';
3
3
  import { _anyToError, ErrorMode } from '@naturalcycles/js-lib/error';
4
- import { pFilter } from '@naturalcycles/js-lib/promise';
5
- import { _stringify } from '@naturalcycles/js-lib/string';
4
+ import { pFilter } from '@naturalcycles/js-lib/promise/pFilter.js';
5
+ import { _stringify } from '@naturalcycles/js-lib/string/stringify.js';
6
6
  import { END, SKIP, } from '@naturalcycles/js-lib/types';
7
7
  import through2Concurrent from 'through2-concurrent';
8
8
  import { yellow } from '../../colors/colors.js';
@@ -1,4 +1,4 @@
1
- import { ErrorMode } from '@naturalcycles/js-lib/error';
1
+ import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js';
2
2
  import type { CommonLogger } from '@naturalcycles/js-lib/log';
3
3
  import type { IndexedMapper } from '@naturalcycles/js-lib/types';
4
4
  import type { TransformTyped } from '../stream.model.js';
@@ -1,5 +1,5 @@
1
1
  import { Transform } from 'node:stream';
2
- import { ErrorMode } from '@naturalcycles/js-lib/error';
2
+ import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js';
3
3
  /**
4
4
  * Simplest version of `transformMap`.
5
5
  * errorMode: IMMEDIATE
@@ -1,5 +1,5 @@
1
1
  import { Transform } from 'node:stream';
2
- import { transformNoOp } from '../index.js';
2
+ import { transformNoOp } from './transformNoOp.js';
3
3
  export function transformOffset(opt) {
4
4
  const { offset } = opt;
5
5
  if (!offset) {
@@ -1,6 +1,6 @@
1
1
  import { Transform } from 'node:stream';
2
2
  import { _ms, _since, localTime } from '@naturalcycles/js-lib/datetime';
3
- import { pDefer } from '@naturalcycles/js-lib/promise';
3
+ import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js';
4
4
  /**
5
5
  * Allows to throttle the throughput of the stream.
6
6
  * For example, when you have an API with rate limit of 5000 requests per minute,
@@ -1,6 +1,6 @@
1
1
  import { Worker } from 'node:worker_threads';
2
- import { _range } from '@naturalcycles/js-lib';
3
- import { pDefer } from '@naturalcycles/js-lib/promise';
2
+ import { _range } from '@naturalcycles/js-lib/array/range.js';
3
+ import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js';
4
4
  import through2Concurrent from 'through2-concurrent';
5
5
  const workerProxyFilePath = `${import.meta.dirname}/workerClassProxy.js`;
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import type { AsyncIndexedMapper, IndexedMapper } from '@naturalcycles/js-lib/types';
2
- import type { TransformMapOptions } from '../index.js';
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
1
  import { _passNothingPredicate } from '@naturalcycles/js-lib/types';
2
- import { transformMap, transformMapSync } from '../index.js';
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 { inspect } from 'node:util';
2
- import { _stringify } from '@naturalcycles/js-lib/string';
2
+ import { _stringify } from '@naturalcycles/js-lib/string/stringify.js';
3
3
  const INSPECT_OPT = {
4
4
  breakLength: 80, // default: ??
5
5
  depth: 10, // default: 2
@@ -1,5 +1,5 @@
1
- import { localTime } from '@naturalcycles/js-lib/datetime';
2
- import { _filterUndefinedValues } from '@naturalcycles/js-lib/object';
1
+ import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
2
+ import { _filterUndefinedValues } from '@naturalcycles/js-lib/object/object.util.js';
3
3
  import { fs2 } from '../fs/fs2.js';
4
4
  import { git2 } from './git2.js';
5
5
  export function generateBuildInfo(opt = {}) {
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
  */
@@ -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,8 +1,7 @@
1
- import { _isObject } from '@naturalcycles/js-lib';
1
+ import { _isObject, _lazyValue } from '@naturalcycles/js-lib';
2
2
  import { JsonSchemaAnyBuilder } from '@naturalcycles/js-lib/json-schema';
3
3
  import { _filterNullishValues } from '@naturalcycles/js-lib/object';
4
4
  import { _substringBefore } from '@naturalcycles/js-lib/string';
5
- import { fs2 } from '../../fs/fs2.js';
6
5
  import { _inspect } from '../../string/inspect.js';
7
6
  import { AjvValidationError } from './ajvValidationError.js';
8
7
  import { getAjv } from './getAjv.js';
@@ -17,23 +16,35 @@ export class AjvSchema {
17
16
  constructor(schema, cfg = {}) {
18
17
  this.schema = schema;
19
18
  this.cfg = {
19
+ lazy: false,
20
20
  ...cfg,
21
- ajv: cfg.ajv ||
22
- getAjv({
23
- schemas: cfg.schemas?.map(s => {
24
- if (s instanceof AjvSchema)
25
- return s.schema;
26
- if (s instanceof JsonSchemaAnyBuilder)
27
- return s.build();
28
- return s;
29
- }),
30
- coerceTypes: cfg.coerceTypes || false,
31
- // verbose: true,
32
- }),
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
+ // }),
33
33
  // Auto-detecting "ObjectName" from $id of the schema (e.g "Address.schema.json")
34
34
  objectName: cfg.objectName || (schema.$id ? _substringBefore(schema.$id, '.') : undefined),
35
35
  };
36
- 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
+ });
37
48
  }
38
49
  /**
39
50
  * Conveniently allows to pass either JsonSchema or JsonSchemaBuilder, or existing AjvSchema.
@@ -52,17 +63,8 @@ export class AjvSchema {
52
63
  }
53
64
  return new AjvSchema(schema, cfg);
54
65
  }
55
- /**
56
- * Create AjvSchema directly from a filePath of json schema.
57
- * Convenient method that just does fs.readFileSync for you.
58
- */
59
- static readJsonSync(filePath, cfg = {}) {
60
- fs2.requireFileToExist(filePath);
61
- const schema = fs2.readJson(filePath);
62
- return new AjvSchema(schema, cfg);
63
- }
64
66
  cfg;
65
- validateFunction;
67
+ getValidateFunction = _lazyValue(() => this.cfg.ajv.compile(this.schema));
66
68
  /**
67
69
  * It returns the original object just for convenience.
68
70
  * Reminder: Ajv will MUTATE your object under 2 circumstances:
@@ -78,12 +80,12 @@ export class AjvSchema {
78
80
  return obj;
79
81
  }
80
82
  isValid(obj) {
81
- return this.validateFunction(obj);
83
+ return this.getValidateFunction()(obj);
82
84
  }
83
85
  getValidationError(obj, opt = {}) {
84
86
  if (this.isValid(obj))
85
87
  return;
86
- const errors = this.validateFunction.errors;
88
+ const errors = this.getValidateFunction().errors;
87
89
  const { objectId = _isObject(obj) ? obj['id'] : undefined, objectName = this.cfg.objectName, } = opt;
88
90
  const name = [objectName || 'Object', objectId].filter(Boolean).join('.');
89
91
  let message = this.cfg.ajv.errorsText(errors, {
@@ -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 { 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/error';
1
+ import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
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,