@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.
- package/dist/bin/slack-this.js +1 -1
- package/dist/cache/lruMemoCache.d.ts +1 -1
- package/dist/csv/csvReader.d.ts +1 -1
- package/dist/csv/csvReader.js +1 -1
- package/dist/csv/csvWriter.d.ts +1 -1
- package/dist/csv/csvWriter.js +1 -1
- package/dist/csv/transformToCSV.d.ts +1 -1
- package/dist/diff/tableDiff.d.ts +1 -1
- package/dist/diff/tableDiff.js +1 -1
- package/dist/{exec2.d.ts → exec2/exec2.d.ts} +2 -2
- package/dist/{exec2.js → exec2/exec2.js} +4 -3
- package/dist/fs/fs2.js +1 -1
- package/dist/fs/json2env.d.ts +1 -1
- package/dist/fs/kpy.js +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/jwt/jwt.service.d.ts +2 -1
- package/dist/jwt/jwt.service.js +1 -1
- package/dist/log/log.util.d.ts +1 -1
- package/dist/log/log.util.js +1 -1
- package/dist/script/runScript.d.ts +2 -1
- package/dist/script/runScript.js +6 -5
- package/dist/secret/secrets-decrypt.util.js +1 -1
- package/dist/secret/secrets-encrypt.util.js +1 -1
- package/dist/security/crypto.util.d.ts +1 -1
- package/dist/security/crypto.util.js +1 -1
- package/dist/security/hash.util.d.ts +1 -1
- package/dist/security/secret.util.d.ts +1 -1
- package/dist/security/secret.util.js +2 -1
- package/dist/slack/index.d.ts +2 -0
- package/dist/slack/index.js +2 -0
- package/dist/slack/slack.service.d.ts +2 -1
- package/dist/slack/slack.service.js +5 -1
- package/dist/slack/slack.service.model.d.ts +3 -2
- package/dist/stream/ndjson/ndjson.model.js +2 -1
- package/dist/stream/ndjson/ndjsonMap.d.ts +1 -1
- package/dist/stream/ndjson/ndjsonMap.js +1 -1
- package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +3 -2
- package/dist/stream/ndjson/ndjsonStreamForEach.js +6 -3
- package/dist/stream/ndjson/transformJsonParse.d.ts +1 -1
- package/dist/stream/ndjson/transformToNDJson.js +1 -1
- package/dist/stream/pipeline/pipeline.d.ts +1 -1
- package/dist/stream/pipeline/pipeline.js +2 -1
- package/dist/stream/progressLogger.d.ts +2 -1
- package/dist/stream/progressLogger.js +3 -1
- package/dist/stream/readable/readableForEach.d.ts +2 -2
- package/dist/stream/readable/readableForEach.js +2 -2
- package/dist/stream/readable/readableFromArray.d.ts +1 -1
- package/dist/stream/readable/readableFromArray.js +1 -1
- package/dist/stream/sizeStack.d.ts +2 -2
- package/dist/stream/sizeStack.js +2 -1
- package/dist/stream/stream.model.d.ts +1 -1
- package/dist/stream/stream.util.d.ts +1 -1
- package/dist/stream/transform/transformFilter.d.ts +1 -1
- package/dist/stream/transform/transformLimit.d.ts +2 -2
- package/dist/stream/transform/transformLimit.js +2 -1
- package/dist/stream/transform/transformMap.d.ts +3 -2
- package/dist/stream/transform/transformMap.js +6 -1
- package/dist/stream/transform/transformMapSimple.d.ts +3 -2
- package/dist/stream/transform/transformMapSimple.js +1 -1
- package/dist/stream/transform/transformMapSync.d.ts +4 -2
- package/dist/stream/transform/transformMapSync.js +2 -1
- package/dist/stream/transform/transformOffset.js +1 -1
- package/dist/stream/transform/transformTap.d.ts +2 -1
- package/dist/stream/transform/transformThrottle.d.ts +1 -1
- package/dist/stream/transform/transformThrottle.js +2 -1
- package/dist/stream/transform/worker/transformMultiThreaded.d.ts +1 -1
- package/dist/stream/transform/worker/transformMultiThreaded.js +2 -1
- package/dist/stream/writable/writableForEach.d.ts +2 -2
- package/dist/stream/writable/writableForEach.js +3 -2
- package/dist/stream/writable/writableFork.js +2 -1
- package/dist/stream/writable/writableVoid.d.ts +1 -1
- package/dist/string/inspect.d.ts +1 -1
- package/dist/string/inspect.js +1 -1
- package/dist/util/buildInfo.util.d.ts +2 -1
- package/dist/util/buildInfo.util.js +2 -1
- package/dist/util/env.util.d.ts +1 -1
- package/dist/util/git2.d.ts +1 -1
- package/dist/util/git2.js +1 -1
- package/dist/validation/ajv/ajvSchema.d.ts +11 -9
- package/dist/validation/ajv/ajvSchema.js +32 -27
- package/dist/validation/ajv/ajvValidationError.d.ts +2 -2
- 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.shared.schemas.d.ts +2 -2
- package/dist/validation/joi/joi.validation.error.d.ts +2 -2
- 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 +4 -1
- package/dist/validation/joi/string.extensions.d.ts +1 -1
- package/dist/validation/joi/string.extensions.js +1 -1
- package/package.json +5 -3
- package/src/bin/generate-build-info.ts +1 -1
- package/src/bin/slack-this.ts +1 -1
- package/src/cache/lruMemoCache.ts +1 -1
- package/src/csv/csvReader.ts +2 -2
- package/src/csv/csvWriter.ts +2 -2
- package/src/csv/transformToCSV.ts +1 -1
- package/src/diff/tableDiff.ts +2 -2
- package/src/{exec2.ts → exec2/exec2.ts} +9 -8
- package/src/fs/fs2.ts +1 -1
- package/src/fs/json2env.ts +1 -1
- package/src/fs/kpy.ts +2 -2
- package/src/index.ts +0 -3
- package/src/jwt/jwt.service.ts +3 -2
- package/src/log/log.util.ts +1 -1
- package/src/script/runScript.ts +8 -8
- package/src/secret/secrets-decrypt.util.ts +1 -1
- package/src/secret/secrets-encrypt.util.ts +1 -1
- package/src/security/crypto.util.ts +1 -2
- package/src/security/hash.util.ts +1 -1
- package/src/security/secret.util.ts +3 -2
- package/src/slack/index.ts +2 -0
- package/src/slack/slack.service.model.ts +3 -2
- package/src/slack/slack.service.ts +11 -4
- package/src/stream/ndjson/ndjson.model.ts +2 -1
- package/src/stream/ndjson/ndjsonMap.ts +2 -2
- package/src/stream/ndjson/ndjsonStreamForEach.ts +8 -6
- package/src/stream/ndjson/transformJsonParse.ts +1 -1
- package/src/stream/ndjson/transformToNDJson.ts +1 -1
- package/src/stream/pipeline/pipeline.ts +4 -2
- package/src/stream/progressLogger.ts +5 -2
- package/src/stream/readable/readableForEach.ts +4 -4
- package/src/stream/readable/readableFromArray.ts +2 -2
- package/src/stream/sizeStack.ts +3 -2
- package/src/stream/stream.model.ts +1 -1
- package/src/stream/stream.util.ts +1 -1
- package/src/stream/transform/transformFilter.ts +1 -1
- package/src/stream/transform/transformLimit.ts +3 -2
- package/src/stream/transform/transformMap.ts +12 -15
- package/src/stream/transform/transformMapSimple.ts +3 -2
- package/src/stream/transform/transformMapSync.ts +4 -7
- package/src/stream/transform/transformOffset.ts +1 -1
- package/src/stream/transform/transformTap.ts +2 -1
- package/src/stream/transform/transformThrottle.ts +4 -3
- package/src/stream/transform/worker/transformMultiThreaded.ts +4 -2
- package/src/stream/writable/writableForEach.ts +4 -4
- package/src/stream/writable/writableFork.ts +3 -3
- package/src/stream/writable/writableVoid.ts +1 -1
- package/src/string/inspect.ts +2 -2
- package/src/util/buildInfo.util.ts +4 -2
- package/src/util/env.util.ts +1 -1
- package/src/util/git2.ts +2 -2
- package/src/validation/ajv/ajvSchema.ts +47 -39
- package/src/validation/ajv/ajvValidationError.ts +2 -2
- package/src/validation/ajv/getAjv.ts +12 -1
- package/src/validation/ajv/index.ts +0 -1
- package/src/validation/joi/joi.shared.schemas.ts +7 -7
- package/src/validation/joi/joi.validation.error.ts +2 -2
- package/src/validation/joi/joi.validation.util.ts +4 -1
- package/src/validation/joi/string.extensions.ts +2 -2
- 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
package/src/script/runScript.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
1
2
|
import os from 'node:os'
|
|
2
|
-
import type {
|
|
3
|
-
import { pDelay
|
|
3
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
4
|
+
import { pDelay } from '@naturalcycles/js-lib/promise'
|
|
5
|
+
import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string'
|
|
6
|
+
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
7
|
+
import { dimGrey } from '../colors/colors.js'
|
|
4
8
|
import { inspectStringifyFn } from '../string/inspect.js'
|
|
5
9
|
|
|
6
10
|
export interface RunScriptOptions {
|
|
@@ -44,6 +48,7 @@ const { DEBUG_RUN_SCRIPT } = process.env
|
|
|
44
48
|
* Set env DEBUG_RUN_SCRIPT for extra debugging.
|
|
45
49
|
*/
|
|
46
50
|
export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
|
|
51
|
+
checkAndlogEnvironment()
|
|
47
52
|
setGlobalStringifyFunction(inspectStringifyFn)
|
|
48
53
|
|
|
49
54
|
const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt
|
|
@@ -67,9 +72,6 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
67
72
|
|
|
68
73
|
void (async () => {
|
|
69
74
|
try {
|
|
70
|
-
await import('dotenv/config')
|
|
71
|
-
await checkAndlogEnvironment()
|
|
72
|
-
|
|
73
75
|
await fn()
|
|
74
76
|
|
|
75
77
|
await pDelay() // to ensure all async operations are completed
|
|
@@ -91,9 +93,7 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
91
93
|
})()
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
|
|
95
|
-
const { dimGrey } = await import('../colors/colors.js')
|
|
96
|
-
|
|
96
|
+
function checkAndlogEnvironment(): void {
|
|
97
97
|
const {
|
|
98
98
|
platform,
|
|
99
99
|
arch,
|
|
@@ -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'
|
|
3
|
+
import { _assert } from '@naturalcycles/js-lib/error'
|
|
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'
|
|
3
|
+
import { _assert } from '@naturalcycles/js-lib/error'
|
|
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,5 @@
|
|
|
1
1
|
import crypto from 'node:crypto'
|
|
2
|
-
import type
|
|
3
|
-
import { _stringMapEntries } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _stringMapEntries, type Base64String, type StringMap } from '@naturalcycles/js-lib/types'
|
|
4
3
|
import { md5AsBuffer, sha256AsBuffer } from './hash.util.js'
|
|
5
4
|
|
|
6
5
|
const algorithm = 'aes-256-cbc'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BinaryToTextEncoding } from 'node:crypto'
|
|
2
2
|
import { hash as cryptoHash } from 'node:crypto'
|
|
3
|
-
import type { Base64String, Base64UrlString } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { Base64String, Base64UrlString } from '@naturalcycles/js-lib/types'
|
|
4
4
|
|
|
5
5
|
export function md5(s: string | Buffer, outputEncoding: BinaryToTextEncoding = 'hex'): string {
|
|
6
6
|
return hash(s, 'md5', outputEncoding)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { _assert } from '@naturalcycles/js-lib/error'
|
|
3
|
+
import { _jsonParseIfPossible } from '@naturalcycles/js-lib/string'
|
|
4
|
+
import type { Base64String, StringMap } from '@naturalcycles/js-lib/types'
|
|
4
5
|
import { decryptObject, decryptRandomIVBuffer } from './crypto.util.js'
|
|
5
6
|
|
|
6
7
|
let loaded = false
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
2
|
+
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
3
|
+
import type { InspectAnyOptions } from '../string/inspect.js'
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Properties that exists both in SlackApiBody (as per Slack API) and SlackMessage (our abstraction).
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { localTime } from '@naturalcycles/js-lib/datetime'
|
|
2
|
+
import { type Fetcher, getFetcher } from '@naturalcycles/js-lib/http'
|
|
3
|
+
import {
|
|
4
|
+
type CommonLogger,
|
|
5
|
+
commonLoggerMinLevel,
|
|
6
|
+
type CommonLogLevel,
|
|
7
|
+
} from '@naturalcycles/js-lib/log'
|
|
8
|
+
import { _omit } from '@naturalcycles/js-lib/object'
|
|
9
|
+
import { PQueue } from '@naturalcycles/js-lib/promise'
|
|
10
|
+
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
11
|
+
import { _inspect, type InspectAnyOptions } from '../index.js'
|
|
5
12
|
import type {
|
|
6
13
|
SlackApiBody,
|
|
7
14
|
SlackAttachmentField,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { ErrorMode } from '@naturalcycles/js-lib/error'
|
|
2
|
+
import type { AbortableAsyncMapper } from '@naturalcycles/js-lib/types'
|
|
3
3
|
import {
|
|
4
4
|
createReadStreamAsNDJSON,
|
|
5
5
|
createWriteStreamAsNDJSON,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { ErrorMode } from '@naturalcycles/js-lib/error'
|
|
2
|
+
import type { AbortableAsyncMapper } from '@naturalcycles/js-lib/types'
|
|
3
|
+
import { _pipeline } from '../pipeline/pipeline.js'
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
+
transformLogProgress,
|
|
5
6
|
type TransformLogProgressOptions,
|
|
6
|
-
|
|
7
|
-
} from '../
|
|
8
|
-
import {
|
|
7
|
+
} from '../transform/transformLogProgress.js'
|
|
8
|
+
import { transformMap, type TransformMapOptions } from '../transform/transformMap.js'
|
|
9
|
+
import { writableVoid } from '../writable/writableVoid.js'
|
|
10
|
+
import { createReadStreamAsNDJSON } from './createReadStreamAsNDJSON.js'
|
|
9
11
|
|
|
10
12
|
export interface NDJSONStreamForEachOptions<IN = any>
|
|
11
13
|
extends TransformMapOptions<IN, void>,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'node:stream'
|
|
2
2
|
import { Transform } from 'node:stream'
|
|
3
3
|
import { pipeline } from 'node:stream/promises'
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import { _last } from '@naturalcycles/js-lib'
|
|
5
|
+
import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
|
|
6
|
+
import { pDefer } from '@naturalcycles/js-lib/promise'
|
|
7
|
+
import type { AnyFunction } from '@naturalcycles/js-lib/types'
|
|
6
8
|
import { writablePushToArray } from '../writable/writablePushToArray.js'
|
|
7
9
|
|
|
8
10
|
type AnyStream = NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { InspectOptions } from 'node:util'
|
|
2
2
|
import { inspect } from 'node:util'
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { _mb } from '@naturalcycles/js-lib'
|
|
4
|
+
import { _since, localTime } from '@naturalcycles/js-lib/datetime'
|
|
5
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
6
|
+
import { SimpleMovingAverage } from '@naturalcycles/js-lib/math'
|
|
7
|
+
import type { AnyObject, UnixTimestampMillis } from '@naturalcycles/js-lib/types'
|
|
5
8
|
import { boldWhite, dimGrey, hasColors, white, yellow } from '../colors/colors.js'
|
|
6
9
|
import { SizeStack } from './sizeStack.js'
|
|
7
10
|
import type { ReadableMapper } from './stream.model.js'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AbortableAsyncMapper, IndexedMapper } from '@naturalcycles/js-lib'
|
|
2
|
-
import { _passNothingPredicate } from '@naturalcycles/js-lib'
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import type { AbortableAsyncMapper, IndexedMapper } from '@naturalcycles/js-lib/types'
|
|
2
|
+
import { _passNothingPredicate } from '@naturalcycles/js-lib/types'
|
|
3
|
+
import { _pipeline } from '../pipeline/pipeline.js'
|
|
4
|
+
import type { ReadableTyped } from '../stream.model.js'
|
|
5
5
|
import type { TransformMapOptions } from '../transform/transformMap.js'
|
|
6
6
|
import { transformMap } from '../transform/transformMap.js'
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReadableOptions } from 'node:stream'
|
|
2
2
|
import { Readable } from 'node:stream'
|
|
3
|
-
import type { AbortableAsyncMapper } from '@naturalcycles/js-lib'
|
|
4
|
-
import { _passthroughMapper } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { AbortableAsyncMapper } from '@naturalcycles/js-lib/types'
|
|
4
|
+
import { _passthroughMapper } from '@naturalcycles/js-lib/types'
|
|
5
5
|
import type { ReadableTyped } from '../stream.model.js'
|
|
6
6
|
|
|
7
7
|
/**
|
package/src/stream/sizeStack.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { _hb } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
+
import { NumberStack } from '@naturalcycles/js-lib/math'
|
|
3
4
|
import { yellow } from '../colors/colors.js'
|
|
4
5
|
import { gzipBuffer } from '../zip/zip.util.js'
|
|
5
6
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Readable, Transform, Writable } from 'node:stream'
|
|
2
|
-
import type { Promisable } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { Promisable } from '@naturalcycles/js-lib/types'
|
|
3
3
|
|
|
4
4
|
export interface ReadableSignalOptions {
|
|
5
5
|
/** allows destroying the stream if the signal is aborted. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
|
-
import type { AsyncPredicate, Predicate } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { AsyncPredicate, Predicate } from '@naturalcycles/js-lib/types'
|
|
3
3
|
import type { TransformOptions, TransformTyped } from '../stream.model.js'
|
|
4
4
|
import type { TransformMapOptions } from './transformMap.js'
|
|
5
5
|
import { transformMap } from './transformMap.js'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream'
|
|
2
|
-
import type { CommonLogger } from '@naturalcycles/js-lib'
|
|
3
|
-
import { AbortableTransform
|
|
2
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
+
import { AbortableTransform } from '../pipeline/pipeline.js'
|
|
4
4
|
import type { TransformOptions, TransformTyped } from '../stream.model.js'
|
|
5
5
|
import { pipelineClose } from '../stream.util.js'
|
|
6
|
+
import { transformNoOp } from './transformNoOp.js'
|
|
6
7
|
|
|
7
8
|
export interface TransformLimitOptions extends TransformOptions {
|
|
8
9
|
/**
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
UnixTimestampMillis,
|
|
8
|
-
} from '@naturalcycles/js-lib'
|
|
1
|
+
import { _hc } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _since } from '@naturalcycles/js-lib/datetime'
|
|
3
|
+
import { _anyToError, ErrorMode } from '@naturalcycles/js-lib/error'
|
|
4
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
5
|
+
import { pFilter } from '@naturalcycles/js-lib/promise'
|
|
6
|
+
import { _stringify } from '@naturalcycles/js-lib/string'
|
|
9
7
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_since,
|
|
13
|
-
_stringify,
|
|
8
|
+
type AbortableAsyncMapper,
|
|
9
|
+
type AsyncPredicate,
|
|
14
10
|
END,
|
|
15
|
-
|
|
16
|
-
pFilter,
|
|
11
|
+
type Promisable,
|
|
17
12
|
SKIP,
|
|
18
|
-
|
|
13
|
+
type StringMap,
|
|
14
|
+
type UnixTimestampMillis,
|
|
15
|
+
} from '@naturalcycles/js-lib/types'
|
|
19
16
|
import through2Concurrent from 'through2-concurrent'
|
|
20
17
|
import { yellow } from '../../colors/colors.js'
|
|
21
18
|
import type { AbortableTransform } from '../pipeline/pipeline.js'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { ErrorMode } from '@naturalcycles/js-lib/error'
|
|
3
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
4
|
+
import type { IndexedMapper } from '@naturalcycles/js-lib/types'
|
|
4
5
|
import type { TransformTyped } from '../stream.model.js'
|
|
5
6
|
|
|
6
7
|
export interface TransformMapSimpleOptions {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
UnixTimestampMillis,
|
|
6
|
-
} from '@naturalcycles/js-lib'
|
|
7
|
-
import { _anyToError, END, ErrorMode, SKIP } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _anyToError, ErrorMode } from '@naturalcycles/js-lib/error'
|
|
2
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
+
import type { IndexedMapper, Predicate, UnixTimestampMillis } from '@naturalcycles/js-lib/types'
|
|
4
|
+
import { END, SKIP } from '@naturalcycles/js-lib/types'
|
|
8
5
|
import { yellow } from '../../colors/colors.js'
|
|
9
6
|
import { AbortableTransform } from '../pipeline/pipeline.js'
|
|
10
7
|
import type { TransformTyped } from '../stream.model.js'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
|
-
import { transformNoOp } from '../index.js'
|
|
3
2
|
import type { TransformOptions, TransformTyped } from '../stream.model.js'
|
|
3
|
+
import { transformNoOp } from './transformNoOp.js'
|
|
4
4
|
|
|
5
5
|
export interface TransformOffsetOptions extends TransformOptions {
|
|
6
6
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
+
import type { AsyncIndexedMapper } from '@naturalcycles/js-lib/types'
|
|
3
4
|
import type { TransformOptions, TransformTyped } from '../stream.model.js'
|
|
4
5
|
|
|
5
6
|
export interface TransformTapOptions extends TransformOptions {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
|
+
import { _ms, _since, localTime } from '@naturalcycles/js-lib/datetime'
|
|
3
|
+
import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
|
|
4
|
+
import { pDefer } from '@naturalcycles/js-lib/promise'
|
|
2
5
|
import type {
|
|
3
|
-
DeferredPromise,
|
|
4
6
|
NumberOfSeconds,
|
|
5
7
|
PositiveInteger,
|
|
6
8
|
UnixTimestampMillis,
|
|
7
|
-
} from '@naturalcycles/js-lib'
|
|
8
|
-
import { _ms, _since, localTime, pDefer } from '@naturalcycles/js-lib'
|
|
9
|
+
} from '@naturalcycles/js-lib/types'
|
|
9
10
|
import type { TransformTyped } from '../stream.model.js'
|
|
10
11
|
|
|
11
12
|
export interface TransformThrottleOptions {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Worker } from 'node:worker_threads'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
2
|
+
import { _range } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
|
|
4
|
+
import { pDefer } from '@naturalcycles/js-lib/promise'
|
|
5
|
+
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
4
6
|
import through2Concurrent from 'through2-concurrent'
|
|
5
7
|
import type { TransformTyped } from '../../stream.model.js'
|
|
6
8
|
import type { WorkerInput, WorkerOutput } from './transformMultiThreaded.model.js'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AsyncIndexedMapper, IndexedMapper } from '@naturalcycles/js-lib'
|
|
2
|
-
import { _passNothingPredicate } from '@naturalcycles/js-lib'
|
|
3
|
-
import type { TransformMapOptions } from '../index.js'
|
|
4
|
-
import { transformMap, transformMapSync } from '../index.js'
|
|
1
|
+
import type { AsyncIndexedMapper, IndexedMapper } from '@naturalcycles/js-lib/types'
|
|
2
|
+
import { _passNothingPredicate } from '@naturalcycles/js-lib/types'
|
|
5
3
|
import type { WritableTyped } from '../stream.model.js'
|
|
4
|
+
import { transformMap, type TransformMapOptions } from '../transform/transformMap.js'
|
|
5
|
+
import { transformMapSync } from '../transform/transformMapSync.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Just an alias to transformMap that declares OUT as void.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Writable } from 'node:stream'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import type { TransformOptions, WritableTyped } from '../stream.model.js'
|
|
2
|
+
import { _pipeline } from '../pipeline/pipeline.js'
|
|
3
|
+
import { readableCreate } from '../readable/readableCreate.js'
|
|
4
|
+
import type { ReadableTyped, TransformOptions, WritableTyped } from '../stream.model.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Allows "forking" a stream inside pipeline into a number of pipeline chains (2 or more).
|
|
@@ -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
|
|
|
5
5
|
export interface WritableVoidOptions extends TransformOptions {
|
package/src/string/inspect.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { InspectOptions } from 'node:util'
|
|
2
2
|
import { inspect } from 'node:util'
|
|
3
|
-
import type { JsonStringifyFunction, StringifyOptions } from '@naturalcycles/js-lib'
|
|
4
|
-
import { _stringify } from '@naturalcycles/js-lib'
|
|
3
|
+
import type { JsonStringifyFunction, StringifyOptions } from '@naturalcycles/js-lib/string'
|
|
4
|
+
import { _stringify } from '@naturalcycles/js-lib/string'
|
|
5
5
|
|
|
6
6
|
export interface InspectAnyOptions extends StringifyOptions, InspectOptions {}
|
|
7
7
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { BuildInfo } from '@naturalcycles/js-lib'
|
|
2
|
+
import { localTime } from '@naturalcycles/js-lib/datetime'
|
|
3
|
+
import { _filterUndefinedValues } from '@naturalcycles/js-lib/object'
|
|
4
|
+
import type { AnyObject, UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
3
5
|
import { fs2 } from '../fs/fs2.js'
|
|
4
6
|
import { git2 } from './git2.js'
|
|
5
7
|
|
package/src/util/env.util.ts
CHANGED
package/src/util/git2.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execSync } from 'node:child_process'
|
|
2
2
|
import { basename } from 'node:path'
|
|
3
|
-
import type { UnixTimestamp } from '@naturalcycles/js-lib'
|
|
4
|
-
import { exec2 } from '../exec2.js'
|
|
3
|
+
import type { UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
4
|
+
import { exec2 } from '../exec2/exec2.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Set of utility functions to work with git.
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@naturalcycles/js-lib'
|
|
8
|
-
import type { Ajv, ValidateFunction } from 'ajv'
|
|
9
|
-
import { fs2 } from '../../fs/fs2.js'
|
|
1
|
+
import { _isObject, _lazyValue } from '@naturalcycles/js-lib'
|
|
2
|
+
import type { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib/json-schema'
|
|
3
|
+
import { JsonSchemaAnyBuilder } from '@naturalcycles/js-lib/json-schema'
|
|
4
|
+
import { _filterNullishValues } from '@naturalcycles/js-lib/object'
|
|
5
|
+
import { _substringBefore } from '@naturalcycles/js-lib/string'
|
|
6
|
+
import type { Ajv } from 'ajv'
|
|
10
7
|
import { _inspect } from '../../string/inspect.js'
|
|
11
8
|
import { AjvValidationError } from './ajvValidationError.js'
|
|
12
9
|
import { getAjv } from './getAjv.js'
|
|
@@ -27,7 +24,7 @@ export interface AjvSchemaCfg {
|
|
|
27
24
|
* Dependent schemas to pass to Ajv instance constructor.
|
|
28
25
|
* Simpler than instantiating and passing ajv instance yourself.
|
|
29
26
|
*/
|
|
30
|
-
schemas?: (JsonSchema | JsonSchemaBuilder | AjvSchema)[]
|
|
27
|
+
// schemas?: (JsonSchema | JsonSchemaBuilder | AjvSchema)[]
|
|
31
28
|
|
|
32
29
|
objectName?: string
|
|
33
30
|
|
|
@@ -38,7 +35,13 @@ export interface AjvSchemaCfg {
|
|
|
38
35
|
*
|
|
39
36
|
* This option is a "shortcut" to skip creating and passing Ajv instance.
|
|
40
37
|
*/
|
|
41
|
-
coerceTypes?: boolean
|
|
38
|
+
// coerceTypes?: boolean
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If true - schema will be compiled on-demand (lazily).
|
|
42
|
+
* Default: false.
|
|
43
|
+
*/
|
|
44
|
+
lazy?: boolean
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/**
|
|
@@ -53,23 +56,40 @@ export class AjvSchema<T = unknown> {
|
|
|
53
56
|
cfg: Partial<AjvSchemaCfg> = {},
|
|
54
57
|
) {
|
|
55
58
|
this.cfg = {
|
|
59
|
+
lazy: false,
|
|
56
60
|
...cfg,
|
|
57
|
-
ajv:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
ajv: cfg.ajv || getAjv(),
|
|
62
|
+
// ajv:
|
|
63
|
+
// cfg.ajv ||
|
|
64
|
+
// getAjv({
|
|
65
|
+
// schemas: cfg.schemas?.map(s => {
|
|
66
|
+
// if (s instanceof AjvSchema) return s.schema
|
|
67
|
+
// if (s instanceof JsonSchemaAnyBuilder) return s.build()
|
|
68
|
+
// return s as JsonSchema
|
|
69
|
+
// }),
|
|
70
|
+
// coerceTypes: cfg.coerceTypes || false,
|
|
71
|
+
// // verbose: true,
|
|
72
|
+
// }),
|
|
68
73
|
// Auto-detecting "ObjectName" from $id of the schema (e.g "Address.schema.json")
|
|
69
74
|
objectName: cfg.objectName || (schema.$id ? _substringBefore(schema.$id, '.') : undefined),
|
|
70
75
|
}
|
|
71
76
|
|
|
72
|
-
|
|
77
|
+
if (!cfg.lazy) {
|
|
78
|
+
this.getValidateFunction() // compile eagerly
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Shortcut for AjvSchema.create(schema, { lazy: true })
|
|
84
|
+
*/
|
|
85
|
+
static createLazy<T>(
|
|
86
|
+
schema: JsonSchemaBuilder<T> | JsonSchema<T> | AjvSchema<T>,
|
|
87
|
+
cfg: Partial<AjvSchemaCfg> = {},
|
|
88
|
+
): AjvSchema<T> {
|
|
89
|
+
return AjvSchema.create(schema, {
|
|
90
|
+
lazy: true,
|
|
91
|
+
...cfg,
|
|
92
|
+
})
|
|
73
93
|
}
|
|
74
94
|
|
|
75
95
|
/**
|
|
@@ -92,21 +112,9 @@ export class AjvSchema<T = unknown> {
|
|
|
92
112
|
return new AjvSchema<T>(schema as JsonSchema<T>, cfg)
|
|
93
113
|
}
|
|
94
114
|
|
|
95
|
-
/**
|
|
96
|
-
* Create AjvSchema directly from a filePath of json schema.
|
|
97
|
-
* Convenient method that just does fs.readFileSync for you.
|
|
98
|
-
*/
|
|
99
|
-
static readJsonSync<T = unknown>(
|
|
100
|
-
filePath: string,
|
|
101
|
-
cfg: Partial<AjvSchemaCfg> = {},
|
|
102
|
-
): AjvSchema<T> {
|
|
103
|
-
fs2.requireFileToExist(filePath)
|
|
104
|
-
const schema = fs2.readJson<JsonSchema<T>>(filePath)
|
|
105
|
-
return new AjvSchema<T>(schema, cfg)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
115
|
readonly cfg: AjvSchemaCfg
|
|
109
|
-
|
|
116
|
+
|
|
117
|
+
private getValidateFunction = _lazyValue(() => this.cfg.ajv.compile<T>(this.schema))
|
|
110
118
|
|
|
111
119
|
/**
|
|
112
120
|
* It returns the original object just for convenience.
|
|
@@ -123,13 +131,13 @@ export class AjvSchema<T = unknown> {
|
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
isValid(obj: T): boolean {
|
|
126
|
-
return this.
|
|
134
|
+
return this.getValidateFunction()(obj)
|
|
127
135
|
}
|
|
128
136
|
|
|
129
137
|
getValidationError(obj: T, opt: AjvValidationOptions = {}): AjvValidationError | undefined {
|
|
130
138
|
if (this.isValid(obj)) return
|
|
131
139
|
|
|
132
|
-
const errors = this.
|
|
140
|
+
const errors = this.getValidateFunction().errors!
|
|
133
141
|
|
|
134
142
|
const {
|
|
135
143
|
objectId = _isObject(obj) ? (obj['id' as keyof T] as any) : undefined,
|
|
@@ -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
|
|
|
5
5
|
export interface AjvValidationErrorData extends ErrorData {
|