@naturalcycles/nodejs-lib 15.3.0 → 15.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/slack-this.js +1 -1
- package/dist/csv/csvReader.js +1 -1
- package/dist/csv/csvWriter.js +1 -1
- package/dist/diff/tableDiff.js +1 -1
- package/dist/{exec2.d.ts → exec2/exec2.d.ts} +1 -1
- package/dist/{exec2.js → exec2/exec2.js} +4 -4
- package/dist/fs/fs2.js +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/jwt/jwt.service.js +2 -1
- package/dist/script/runScript.d.ts +1 -0
- package/dist/script/runScript.js +6 -6
- package/dist/secret/secrets-decrypt.util.js +1 -1
- package/dist/secret/secrets-encrypt.util.js +1 -1
- package/dist/security/secret.util.js +2 -2
- package/dist/slack/index.d.ts +2 -0
- package/dist/slack/index.js +2 -0
- package/dist/slack/slack.service.js +3 -3
- package/dist/slack/slack.service.model.d.ts +1 -1
- package/dist/stream/ndjson/ndjson.model.js +1 -1
- package/dist/stream/ndjson/ndjsonMap.js +1 -1
- package/dist/stream/ndjson/ndjsonStreamForEach.d.ts +2 -1
- package/dist/stream/ndjson/ndjsonStreamForEach.js +6 -3
- package/dist/stream/pipeline/pipeline.js +2 -2
- package/dist/stream/readable/readableForEach.d.ts +1 -1
- package/dist/stream/readable/readableForEach.js +1 -1
- package/dist/stream/sizeStack.d.ts +1 -1
- package/dist/stream/sizeStack.js +1 -1
- package/dist/stream/transform/transformLimit.d.ts +1 -1
- package/dist/stream/transform/transformLimit.js +2 -1
- package/dist/stream/transform/transformMap.js +3 -3
- package/dist/stream/transform/transformMapSimple.d.ts +1 -1
- package/dist/stream/transform/transformMapSimple.js +1 -1
- package/dist/stream/transform/transformOffset.js +1 -1
- package/dist/stream/transform/transformThrottle.js +1 -1
- package/dist/stream/transform/worker/transformMultiThreaded.js +2 -2
- package/dist/stream/writable/writableForEach.d.ts +1 -1
- package/dist/stream/writable/writableForEach.js +2 -1
- package/dist/stream/writable/writableFork.js +2 -1
- package/dist/string/inspect.js +1 -1
- package/dist/util/buildInfo.util.js +2 -2
- package/dist/util/git2.js +1 -1
- package/dist/validation/ajv/ajvSchema.d.ts +10 -8
- package/dist/validation/ajv/ajvSchema.js +29 -27
- package/dist/validation/ajv/ajvValidationError.d.ts +1 -1
- package/dist/validation/ajv/ajvValidationError.js +1 -1
- package/dist/validation/ajv/getAjv.d.ts +10 -1
- package/dist/validation/ajv/getAjv.js +11 -1
- package/dist/validation/ajv/index.d.ts +0 -1
- package/dist/validation/ajv/index.js +0 -1
- package/dist/validation/joi/joi.validation.error.d.ts +1 -1
- package/dist/validation/joi/joi.validation.error.js +1 -1
- package/dist/validation/joi/joi.validation.util.d.ts +2 -0
- package/dist/validation/joi/joi.validation.util.js +3 -1
- package/dist/validation/joi/string.extensions.js +1 -1
- package/package.json +7 -5
- package/src/bin/slack-this.ts +1 -1
- package/src/csv/csvReader.ts +1 -1
- package/src/csv/csvWriter.ts +1 -1
- package/src/diff/tableDiff.ts +1 -1
- package/src/{exec2.ts → exec2/exec2.ts} +4 -4
- package/src/fs/fs2.ts +1 -1
- package/src/index.ts +0 -3
- package/src/jwt/jwt.service.ts +2 -1
- package/src/script/runScript.ts +6 -8
- package/src/secret/secrets-decrypt.util.ts +1 -1
- package/src/secret/secrets-encrypt.util.ts +1 -1
- package/src/security/secret.util.ts +2 -2
- package/src/slack/index.ts +2 -0
- package/src/slack/slack.service.model.ts +1 -1
- package/src/slack/slack.service.ts +4 -5
- package/src/stream/ndjson/ndjson.model.ts +1 -1
- package/src/stream/ndjson/ndjsonMap.ts +1 -1
- package/src/stream/ndjson/ndjsonStreamForEach.ts +7 -5
- package/src/stream/pipeline/pipeline.ts +2 -2
- package/src/stream/readable/readableForEach.ts +2 -2
- package/src/stream/sizeStack.ts +1 -1
- package/src/stream/transform/transformLimit.ts +2 -1
- package/src/stream/transform/transformMap.ts +3 -3
- package/src/stream/transform/transformMapSimple.ts +1 -1
- package/src/stream/transform/transformOffset.ts +1 -1
- package/src/stream/transform/transformThrottle.ts +1 -1
- package/src/stream/transform/worker/transformMultiThreaded.ts +2 -2
- package/src/stream/writable/writableForEach.ts +2 -2
- package/src/stream/writable/writableFork.ts +3 -3
- package/src/string/inspect.ts +1 -1
- package/src/util/buildInfo.util.ts +2 -2
- package/src/util/git2.ts +1 -1
- package/src/validation/ajv/ajvSchema.ts +43 -33
- package/src/validation/ajv/ajvValidationError.ts +1 -1
- package/src/validation/ajv/getAjv.ts +12 -1
- package/src/validation/ajv/index.ts +0 -1
- package/src/validation/joi/joi.validation.error.ts +1 -1
- package/src/validation/joi/joi.validation.util.ts +3 -1
- package/src/validation/joi/string.extensions.ts +1 -1
- package/dist/validation/ajv/ajv.util.d.ts +0 -21
- package/dist/validation/ajv/ajv.util.js +0 -28
- package/src/validation/ajv/ajv.util.ts +0 -38
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ErrorData } from '@naturalcycles/js-lib/error';
|
|
2
|
-
import { AppError } from '@naturalcycles/js-lib/error';
|
|
2
|
+
import { AppError } from '@naturalcycles/js-lib/error/error.util.js';
|
|
3
3
|
import type { ValidationErrorItem } from 'joi';
|
|
4
4
|
/**
|
|
5
5
|
* Example of ValidationErrorItem:
|
|
@@ -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>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* "Converts" mean e.g trims all strings from leading/trailing spaces.
|
|
7
7
|
*/
|
|
8
8
|
import { _hb, _isObject } from '@naturalcycles/js-lib';
|
|
9
|
-
import { _truncateMiddle } from '@naturalcycles/js-lib/string';
|
|
9
|
+
import { _truncateMiddle } from '@naturalcycles/js-lib/string/string.util.js';
|
|
10
10
|
import { JoiValidationError } from './joi.validation.error.js';
|
|
11
11
|
// Strip colors in production (for e.g Sentry reporting)
|
|
12
12
|
// const stripColors = process.env.NODE_ENV === 'production' || !!process.env.GAE_INSTANCE
|
|
@@ -50,6 +50,8 @@ export function validate(input, schema, objectName, opt = {}) {
|
|
|
50
50
|
* Returns JoiValidationResult with converted value and error (if any).
|
|
51
51
|
* Does not throw.
|
|
52
52
|
*
|
|
53
|
+
* Joi does NOT mutate the input.
|
|
54
|
+
*
|
|
53
55
|
* If `schema` is undefined - returns value as is.
|
|
54
56
|
*/
|
|
55
57
|
export function getValidationResult(input, schema, objectName, options = {}) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.5.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@types/js-yaml": "^4",
|
|
@@ -22,22 +22,25 @@
|
|
|
22
22
|
"yargs": "^18"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
25
|
+
"@types/through2-concurrent": "^2",
|
|
26
|
+
"@naturalcycles/dev-lib": "19.11.0"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
".": "./dist/index.js",
|
|
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"
|
package/src/bin/slack-this.ts
CHANGED
package/src/csv/csvReader.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Inspired by: https://gist.github.com/Jezternz/c8e9fafc2c114e079829974e3764db75
|
|
2
2
|
|
|
3
|
-
import { _assert } from '@naturalcycles/js-lib/error'
|
|
3
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
4
4
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
5
5
|
|
|
6
6
|
export interface CSVReaderConfig {
|
package/src/csv/csvWriter.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Inspired by: https://github.com/ryu1kn/csv-writer/
|
|
2
2
|
|
|
3
|
-
import { _assert } from '@naturalcycles/js-lib/error'
|
|
3
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
4
4
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
5
5
|
|
|
6
6
|
export interface CSVWriterConfig {
|
package/src/diff/tableDiff.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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'
|
|
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
5
|
import type {
|
|
6
6
|
AnyObject,
|
|
7
7
|
NumberOfMilliseconds,
|
|
8
8
|
UnixTimestampMillis,
|
|
9
9
|
} from '@naturalcycles/js-lib/types'
|
|
10
|
-
import { dimGrey, dimRed, hasColors, white } from '
|
|
10
|
+
import { dimGrey, dimRed, hasColors, white } from '../colors/colors.js'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
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/string'
|
|
21
|
+
import { _jsonParse } from '@naturalcycles/js-lib/string/json.util.js'
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* fs2 conveniently groups filesystem functions together.
|
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'
|
package/src/jwt/jwt.service.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ErrorData } from '@naturalcycles/js-lib/error'
|
|
2
|
-
import { _assert
|
|
2
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
3
|
+
import { _errorDataAppend } from '@naturalcycles/js-lib/error/error.util.js'
|
|
3
4
|
import type { AnyObject, JWTString } from '@naturalcycles/js-lib/types'
|
|
4
5
|
import type { AnySchema } from 'joi'
|
|
5
6
|
import type { Algorithm, JwtHeader, SignOptions, VerifyOptions } from 'jsonwebtoken'
|
package/src/script/runScript.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import 'dotenv/config'
|
|
1
2
|
import os from 'node:os'
|
|
2
3
|
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
-
import { pDelay } from '@naturalcycles/js-lib/promise'
|
|
4
|
-
import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string'
|
|
4
|
+
import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js'
|
|
5
|
+
import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string/stringify.js'
|
|
5
6
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
7
|
+
import { dimGrey } from '../colors/colors.js'
|
|
6
8
|
import { inspectStringifyFn } from '../string/inspect.js'
|
|
7
9
|
|
|
8
10
|
export interface RunScriptOptions {
|
|
@@ -46,6 +48,7 @@ const { DEBUG_RUN_SCRIPT } = process.env
|
|
|
46
48
|
* Set env DEBUG_RUN_SCRIPT for extra debugging.
|
|
47
49
|
*/
|
|
48
50
|
export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {}): void {
|
|
51
|
+
checkAndlogEnvironment()
|
|
49
52
|
setGlobalStringifyFunction(inspectStringifyFn)
|
|
50
53
|
|
|
51
54
|
const { logger = console, noExit, registerUncaughtExceptionHandlers = true } = opt
|
|
@@ -69,9 +72,6 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
69
72
|
|
|
70
73
|
void (async () => {
|
|
71
74
|
try {
|
|
72
|
-
await import('dotenv/config')
|
|
73
|
-
await checkAndlogEnvironment()
|
|
74
|
-
|
|
75
75
|
await fn()
|
|
76
76
|
|
|
77
77
|
await pDelay() // to ensure all async operations are completed
|
|
@@ -93,9 +93,7 @@ export function runScript(fn: (...args: any[]) => any, opt: RunScriptOptions = {
|
|
|
93
93
|
})()
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
const { dimGrey } = await import('../colors/colors.js')
|
|
98
|
-
|
|
96
|
+
function checkAndlogEnvironment(): void {
|
|
99
97
|
const {
|
|
100
98
|
platform,
|
|
101
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/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 type { Base64String, StringMap } from '@naturalcycles/js-lib/types'
|
|
5
5
|
import { decryptObject, decryptRandomIVBuffer } from './crypto.util.js'
|
|
6
6
|
|
|
@@ -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 '../
|
|
3
|
+
import type { InspectAnyOptions } from '../string/inspect.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Properties that exists both in SlackApiBody (as per Slack API) and SlackMessage (our abstraction).
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { localTime } from '@naturalcycles/js-lib/datetime'
|
|
1
|
+
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
|
|
2
2
|
import { type Fetcher, getFetcher } from '@naturalcycles/js-lib/http'
|
|
3
3
|
import {
|
|
4
4
|
type CommonLogger,
|
|
5
5
|
commonLoggerMinLevel,
|
|
6
6
|
type CommonLogLevel,
|
|
7
7
|
} from '@naturalcycles/js-lib/log'
|
|
8
|
-
import { _omit } from '@naturalcycles/js-lib/object'
|
|
9
|
-
import { PQueue } from '@naturalcycles/js-lib/promise'
|
|
8
|
+
import { _omit } from '@naturalcycles/js-lib/object/object.util.js'
|
|
9
|
+
import { PQueue } from '@naturalcycles/js-lib/promise/pQueue.js'
|
|
10
10
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
11
|
-
import type
|
|
12
|
-
import { _inspect } from '../index.js'
|
|
11
|
+
import { _inspect, type InspectAnyOptions } from '../index.js'
|
|
13
12
|
import type {
|
|
14
13
|
SlackApiBody,
|
|
15
14
|
SlackAttachmentField,
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { ErrorMode } from '@naturalcycles/js-lib/error'
|
|
1
|
+
import { ErrorMode } from '@naturalcycles/js-lib/error/errorMode.js'
|
|
2
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,9 +1,9 @@
|
|
|
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 { _last } from '@naturalcycles/js-lib'
|
|
4
|
+
import { _last } from '@naturalcycles/js-lib/array/array.util.js'
|
|
5
5
|
import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
|
|
6
|
-
import { pDefer } from '@naturalcycles/js-lib/promise'
|
|
6
|
+
import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
|
|
7
7
|
import type { AnyFunction } from '@naturalcycles/js-lib/types'
|
|
8
8
|
import { writablePushToArray } from '../writable/writablePushToArray.js'
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbortableAsyncMapper, IndexedMapper } from '@naturalcycles/js-lib/types'
|
|
2
2
|
import { _passNothingPredicate } from '@naturalcycles/js-lib/types'
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
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
|
|
package/src/stream/sizeStack.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { _hb } from '@naturalcycles/js-lib'
|
|
2
2
|
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
-
import { NumberStack } from '@naturalcycles/js-lib/math'
|
|
3
|
+
import { NumberStack } from '@naturalcycles/js-lib/math/stack.util.js'
|
|
4
4
|
import { yellow } from '../colors/colors.js'
|
|
5
5
|
import { gzipBuffer } from '../zip/zip.util.js'
|
|
6
6
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Readable } from 'node:stream'
|
|
2
2
|
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
3
|
-
import { AbortableTransform
|
|
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,9 +1,9 @@
|
|
|
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
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'
|
|
5
|
+
import { pFilter } from '@naturalcycles/js-lib/promise/pFilter.js'
|
|
6
|
+
import { _stringify } from '@naturalcycles/js-lib/string/stringify.js'
|
|
7
7
|
import {
|
|
8
8
|
type AbortableAsyncMapper,
|
|
9
9
|
type AsyncPredicate,
|
|
@@ -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
|
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
4
4
|
import type { IndexedMapper } from '@naturalcycles/js-lib/types'
|
|
5
5
|
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,7 +1,7 @@
|
|
|
1
1
|
import { Transform } from 'node:stream'
|
|
2
2
|
import { _ms, _since, localTime } from '@naturalcycles/js-lib/datetime'
|
|
3
3
|
import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
|
|
4
|
-
import { pDefer } from '@naturalcycles/js-lib/promise'
|
|
4
|
+
import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
|
|
5
5
|
import type {
|
|
6
6
|
NumberOfSeconds,
|
|
7
7
|
PositiveInteger,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Worker } from 'node:worker_threads'
|
|
2
|
-
import { _range } from '@naturalcycles/js-lib'
|
|
2
|
+
import { _range } from '@naturalcycles/js-lib/array/range.js'
|
|
3
3
|
import type { DeferredPromise } from '@naturalcycles/js-lib/promise'
|
|
4
|
-
import { pDefer } from '@naturalcycles/js-lib/promise'
|
|
4
|
+
import { pDefer } from '@naturalcycles/js-lib/promise/pDefer.js'
|
|
5
5
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
6
6
|
import through2Concurrent from 'through2-concurrent'
|
|
7
7
|
import type { TransformTyped } from '../../stream.model.js'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AsyncIndexedMapper, IndexedMapper } from '@naturalcycles/js-lib/types'
|
|
2
2
|
import { _passNothingPredicate } from '@naturalcycles/js-lib/types'
|
|
3
|
-
import type { TransformMapOptions } from '../index.js'
|
|
4
|
-
import { transformMap, transformMapSync } from '../index.js'
|
|
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).
|
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
3
|
import type { JsonStringifyFunction, StringifyOptions } from '@naturalcycles/js-lib/string'
|
|
4
|
-
import { _stringify } from '@naturalcycles/js-lib/string'
|
|
4
|
+
import { _stringify } from '@naturalcycles/js-lib/string/stringify.js'
|
|
5
5
|
|
|
6
6
|
export interface InspectAnyOptions extends StringifyOptions, InspectOptions {}
|
|
7
7
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuildInfo } from '@naturalcycles/js-lib'
|
|
2
|
-
import { localTime } from '@naturalcycles/js-lib/datetime'
|
|
3
|
-
import { _filterUndefinedValues } from '@naturalcycles/js-lib/object'
|
|
2
|
+
import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
|
|
3
|
+
import { _filterUndefinedValues } from '@naturalcycles/js-lib/object/object.util.js'
|
|
4
4
|
import type { AnyObject, UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
5
5
|
import { fs2 } from '../fs/fs2.js'
|
|
6
6
|
import { git2 } from './git2.js'
|
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
3
|
import type { UnixTimestamp } from '@naturalcycles/js-lib/types'
|
|
4
|
-
import { exec2 } from '../exec2.js'
|
|
4
|
+
import { exec2 } from '../exec2/exec2.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Set of utility functions to work with git.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { _isObject } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _isObject, _lazyValue } from '@naturalcycles/js-lib'
|
|
2
2
|
import type { JsonSchema, JsonSchemaBuilder } from '@naturalcycles/js-lib/json-schema'
|
|
3
3
|
import { JsonSchemaAnyBuilder } from '@naturalcycles/js-lib/json-schema'
|
|
4
4
|
import { _filterNullishValues } from '@naturalcycles/js-lib/object'
|
|
5
5
|
import { _substringBefore } from '@naturalcycles/js-lib/string'
|
|
6
|
-
import type { Ajv
|
|
7
|
-
import { fs2 } from '../../fs/fs2.js'
|
|
6
|
+
import type { Ajv } from 'ajv'
|
|
8
7
|
import { _inspect } from '../../string/inspect.js'
|
|
9
8
|
import { AjvValidationError } from './ajvValidationError.js'
|
|
10
9
|
import { getAjv } from './getAjv.js'
|
|
@@ -25,7 +24,7 @@ export interface AjvSchemaCfg {
|
|
|
25
24
|
* Dependent schemas to pass to Ajv instance constructor.
|
|
26
25
|
* Simpler than instantiating and passing ajv instance yourself.
|
|
27
26
|
*/
|
|
28
|
-
schemas?: (JsonSchema | JsonSchemaBuilder | AjvSchema)[]
|
|
27
|
+
// schemas?: (JsonSchema | JsonSchemaBuilder | AjvSchema)[]
|
|
29
28
|
|
|
30
29
|
objectName?: string
|
|
31
30
|
|
|
@@ -36,7 +35,13 @@ export interface AjvSchemaCfg {
|
|
|
36
35
|
*
|
|
37
36
|
* This option is a "shortcut" to skip creating and passing Ajv instance.
|
|
38
37
|
*/
|
|
39
|
-
coerceTypes?: boolean
|
|
38
|
+
// coerceTypes?: boolean
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* If true - schema will be compiled on-demand (lazily).
|
|
42
|
+
* Default: false.
|
|
43
|
+
*/
|
|
44
|
+
lazy?: boolean
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
/**
|
|
@@ -51,23 +56,40 @@ export class AjvSchema<T = unknown> {
|
|
|
51
56
|
cfg: Partial<AjvSchemaCfg> = {},
|
|
52
57
|
) {
|
|
53
58
|
this.cfg = {
|
|
59
|
+
lazy: false,
|
|
54
60
|
...cfg,
|
|
55
|
-
ajv:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
// }),
|
|
66
73
|
// Auto-detecting "ObjectName" from $id of the schema (e.g "Address.schema.json")
|
|
67
74
|
objectName: cfg.objectName || (schema.$id ? _substringBefore(schema.$id, '.') : undefined),
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
|
|
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
|
+
})
|
|
71
93
|
}
|
|
72
94
|
|
|
73
95
|
/**
|
|
@@ -90,21 +112,9 @@ export class AjvSchema<T = unknown> {
|
|
|
90
112
|
return new AjvSchema<T>(schema as JsonSchema<T>, cfg)
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
/**
|
|
94
|
-
* Create AjvSchema directly from a filePath of json schema.
|
|
95
|
-
* Convenient method that just does fs.readFileSync for you.
|
|
96
|
-
*/
|
|
97
|
-
static readJsonSync<T = unknown>(
|
|
98
|
-
filePath: string,
|
|
99
|
-
cfg: Partial<AjvSchemaCfg> = {},
|
|
100
|
-
): AjvSchema<T> {
|
|
101
|
-
fs2.requireFileToExist(filePath)
|
|
102
|
-
const schema = fs2.readJson<JsonSchema<T>>(filePath)
|
|
103
|
-
return new AjvSchema<T>(schema, cfg)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
115
|
readonly cfg: AjvSchemaCfg
|
|
107
|
-
|
|
116
|
+
|
|
117
|
+
private getValidateFunction = _lazyValue(() => this.cfg.ajv.compile<T>(this.schema))
|
|
108
118
|
|
|
109
119
|
/**
|
|
110
120
|
* It returns the original object just for convenience.
|
|
@@ -121,13 +131,13 @@ export class AjvSchema<T = unknown> {
|
|
|
121
131
|
}
|
|
122
132
|
|
|
123
133
|
isValid(obj: T): boolean {
|
|
124
|
-
return this.
|
|
134
|
+
return this.getValidateFunction()(obj)
|
|
125
135
|
}
|
|
126
136
|
|
|
127
137
|
getValidationError(obj: T, opt: AjvValidationOptions = {}): AjvValidationError | undefined {
|
|
128
138
|
if (this.isValid(obj)) return
|
|
129
139
|
|
|
130
|
-
const errors = this.
|
|
140
|
+
const errors = this.getValidateFunction().errors!
|
|
131
141
|
|
|
132
142
|
const {
|
|
133
143
|
objectId = _isObject(obj) ? (obj['id' as keyof T] as any) : undefined,
|
|
@@ -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
|
|
|
5
5
|
export interface AjvValidationErrorData extends ErrorData {
|