@naturalcycles/nodejs-lib 14.0.2 → 14.1.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/fs/kpy.js +4 -3
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -2
- package/dist/log/log.util.js +1 -1
- package/dist/secret/secrets-decrypt.util.js +3 -2
- package/dist/secret/secrets-encrypt.util.js +3 -2
- package/dist/validation/ajv/ajv.util.d.ts +2 -2
- package/dist/validation/ajv/ajv.util.js +3 -2
- package/dist/validation/ajv/ajvSchema.js +3 -1
- package/package.json +2 -3
- package/src/fs/kpy.ts +4 -3
- package/src/index.ts +2 -4
- package/src/log/log.util.ts +1 -1
- package/src/secret/secrets-decrypt.util.ts +3 -2
- package/src/secret/secrets-encrypt.util.ts +3 -2
- package/src/validation/ajv/ajv.util.ts +8 -4
- package/src/validation/ajv/ajvSchema.ts +3 -1
package/dist/fs/kpy.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { _since, localTime } from '@naturalcycles/js-lib';
|
|
3
|
+
import { glob, globSync } from 'tinyglobby';
|
|
3
4
|
import { boldWhite, dimGrey, grey, yellow } from '../colors/colors.js';
|
|
4
|
-
import {
|
|
5
|
+
import { fs2 } from './fs2.js';
|
|
5
6
|
export async function kpy(opt) {
|
|
6
7
|
const started = localTime.nowUnixMillis();
|
|
7
8
|
kpyPrepare(opt);
|
|
8
|
-
const filenames = await
|
|
9
|
+
const filenames = await glob(opt.inputPatterns, {
|
|
9
10
|
cwd: opt.baseDir,
|
|
10
11
|
dot: opt.dotfiles,
|
|
11
12
|
});
|
|
@@ -34,7 +35,7 @@ export async function kpy(opt) {
|
|
|
34
35
|
export function kpySync(opt) {
|
|
35
36
|
const started = localTime.nowUnixMillis();
|
|
36
37
|
kpyPrepare(opt);
|
|
37
|
-
const filenames =
|
|
38
|
+
const filenames = globSync(opt.inputPatterns, {
|
|
38
39
|
cwd: opt.baseDir,
|
|
39
40
|
dot: opt.dotfiles,
|
|
40
41
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
|
|
3
|
-
import fastGlob from 'fast-glob';
|
|
2
|
+
export { glob, globSync } from 'tinyglobby';
|
|
4
3
|
import type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema, ValidationErrorItem } from 'joi';
|
|
5
4
|
export * from './buffer/buffer.util.js';
|
|
6
5
|
export * from './colors/colors.js';
|
|
@@ -73,5 +72,5 @@ export * from './validation/joi/joi.validation.error.js';
|
|
|
73
72
|
export * from './validation/joi/joi.validation.util.js';
|
|
74
73
|
export type { StringSchema } from './validation/joi/string.extensions.js';
|
|
75
74
|
export * from './yargs.util.js';
|
|
76
|
-
export type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema,
|
|
77
|
-
export { Ajv
|
|
75
|
+
export type { AlternativesSchema, AnySchema, ArraySchema, BinarySchema, BooleanSchema, DateSchema, FunctionSchema, ObjectSchema, ValidationErrorItem, };
|
|
76
|
+
export { Ajv };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
|
|
2
|
+
export { glob, globSync } from 'tinyglobby';
|
|
3
3
|
export * from './buffer/buffer.util.js';
|
|
4
4
|
export * from './colors/colors.js';
|
|
5
5
|
export * from './csv/csvReader.js';
|
|
@@ -70,4 +70,4 @@ export * from './validation/joi/joi.shared.schemas.js';
|
|
|
70
70
|
export * from './validation/joi/joi.validation.error.js';
|
|
71
71
|
export * from './validation/joi/joi.validation.util.js';
|
|
72
72
|
export * from './yargs.util.js';
|
|
73
|
-
export { Ajv
|
|
73
|
+
export { Ajv };
|
package/dist/log/log.util.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib';
|
|
4
|
+
import { globSync } from 'tinyglobby';
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js';
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js';
|
|
6
7
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js';
|
|
7
8
|
// Debug it like this:
|
|
8
9
|
// yarn tsx scripts/./src/bin/secrets-encrypt.ts --file ./src/test/secrets2.plain.json --jsonMode --encKey MPd/30v0Zcce4I5mfwF4NSXrpTYD9OO4/fIqw6rjNiWp2b1GN9Xm8nQZqr7c9kKSsATqtwe0HkJFDUGzDSow44GDgDICgB1u1rGa5eNqtxnOVGRR+lIinCvN/1OnpjzeoJy2bStXPj1DKx8anMqgA8SoOZdlWRNSkEeZlolru8Ey0ujZo22dfwMyRIEniLcqvBm/iMiAkV82fn/TxYw05GarAoJcrfPeDBvuOXsARnMCyX18qTFL0iojxeTU8JHxr8TX3eXDq9cJJmridEKlwRIAzADwtetI4ttlP8lwJj1pmgsBIN3iqYssZYCkZ3HMV6BoEc7LTI5z/45rKrAT1A==
|
|
@@ -16,7 +17,7 @@ import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js
|
|
|
16
17
|
export function secretsDecrypt(dir, file, encKeyBuffer, del = false, jsonMode = false) {
|
|
17
18
|
// If `file` is provided - only this one file is used
|
|
18
19
|
const patterns = file ? [file] : dir.map(d => `${d}/**/*.enc`);
|
|
19
|
-
const filenames =
|
|
20
|
+
const filenames = globSync(patterns);
|
|
20
21
|
filenames.forEach(filename => {
|
|
21
22
|
let plainFilename;
|
|
22
23
|
if (jsonMode) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib';
|
|
4
|
+
import { globSync } from 'tinyglobby';
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js';
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js';
|
|
6
7
|
import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util.js';
|
|
7
8
|
/**
|
|
8
9
|
* Encrypts all files in given directory (except *.enc), saves encrypted versions as filename.ext.enc.
|
|
@@ -15,7 +16,7 @@ export function secretsEncrypt(pattern, file, encKeyBuffer, del = false, jsonMod
|
|
|
15
16
|
...pattern,
|
|
16
17
|
`!**/*.enc`, // excluding already encoded
|
|
17
18
|
];
|
|
18
|
-
const filenames =
|
|
19
|
+
const filenames = globSync(patterns);
|
|
19
20
|
let encFilename;
|
|
20
21
|
filenames.forEach(filename => {
|
|
21
22
|
if (jsonMode) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { JsonSchema } from '@naturalcycles/js-lib';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobOptions } from 'tinyglobby';
|
|
3
3
|
import type { AjvSchemaCfg } from './ajvSchema.js';
|
|
4
4
|
import { AjvSchema } from './ajvSchema.js';
|
|
5
5
|
/**
|
|
@@ -10,7 +10,7 @@ import { AjvSchema } from './ajvSchema.js';
|
|
|
10
10
|
*
|
|
11
11
|
* @experimental
|
|
12
12
|
*/
|
|
13
|
-
export declare function readJsonSchemas(patterns: string | string[], opt?:
|
|
13
|
+
export declare function readJsonSchemas(patterns: string | string[], opt?: Omit<GlobOptions, 'patterns'>): JsonSchema[];
|
|
14
14
|
/**
|
|
15
15
|
* Reads json schemas from given dir (glob pattern).
|
|
16
16
|
* Creates new AjvSchema for each of them (ajv validates them upon creation).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globSync } from 'tinyglobby';
|
|
2
|
+
import { fs2 } from '../../fs/fs2.js';
|
|
2
3
|
import { AjvSchema } from './ajvSchema.js';
|
|
3
4
|
/**
|
|
4
5
|
* Does fs.readFileSync + JSON.parse for ALL files matching the passed `glob` pattern.
|
|
@@ -9,7 +10,7 @@ import { AjvSchema } from './ajvSchema.js';
|
|
|
9
10
|
* @experimental
|
|
10
11
|
*/
|
|
11
12
|
export function readJsonSchemas(patterns, opt) {
|
|
12
|
-
return
|
|
13
|
+
return globSync(patterns, opt).map(fileName => fs2.readJson(fileName));
|
|
13
14
|
}
|
|
14
15
|
/**
|
|
15
16
|
* Reads json schemas from given dir (glob pattern).
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { _filterNullishValues, _isObject, _substringBefore, JsonSchemaAnyBuilder, } from '@naturalcycles/js-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { fs2 } from '../../fs/fs2.js';
|
|
3
|
+
import { _inspect } from '../../string/inspect.js';
|
|
4
|
+
import { requireFileToExist } from '../../util/env.util.js';
|
|
3
5
|
import { AjvValidationError } from './ajvValidationError.js';
|
|
4
6
|
import { getAjv } from './getAjv.js';
|
|
5
7
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "14.0
|
|
4
|
+
"version": "14.1.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepare": "husky",
|
|
7
7
|
"build": "dev-lib build",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"ajv-keywords": "^5",
|
|
31
31
|
"chalk": "^5",
|
|
32
32
|
"dotenv": "^16",
|
|
33
|
-
"fast-glob": "^3",
|
|
34
33
|
"joi": "^17",
|
|
35
34
|
"js-yaml": "^4",
|
|
36
35
|
"jsonwebtoken": "^9",
|
|
37
36
|
"lru-cache": "^11",
|
|
38
37
|
"through2-concurrent": "^2",
|
|
38
|
+
"tinyglobby": "^0.2",
|
|
39
39
|
"yargs": "^17"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@naturalcycles/dev-lib": "^18",
|
|
44
44
|
"@types/node": "^22",
|
|
45
45
|
"@types/through2-concurrent": "^2",
|
|
46
|
-
"@vitest/coverage-v8": "^3",
|
|
47
46
|
"tsx": "^4",
|
|
48
47
|
"vitest": "^3"
|
|
49
48
|
},
|
package/src/fs/kpy.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import type { UnixTimestampMillis } from '@naturalcycles/js-lib'
|
|
3
3
|
import { _since, localTime } from '@naturalcycles/js-lib'
|
|
4
|
+
import { glob, globSync } from 'tinyglobby'
|
|
4
5
|
import { boldWhite, dimGrey, grey, yellow } from '../colors/colors.js'
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from './fs2.js'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Everything defaults to `undefined`.
|
|
@@ -48,7 +49,7 @@ export async function kpy(opt: KpyOptions): Promise<void> {
|
|
|
48
49
|
|
|
49
50
|
kpyPrepare(opt)
|
|
50
51
|
|
|
51
|
-
const filenames = await
|
|
52
|
+
const filenames = await glob(opt.inputPatterns!, {
|
|
52
53
|
cwd: opt.baseDir,
|
|
53
54
|
dot: opt.dotfiles,
|
|
54
55
|
})
|
|
@@ -87,7 +88,7 @@ export function kpySync(opt: KpyOptions): void {
|
|
|
87
88
|
|
|
88
89
|
kpyPrepare(opt)
|
|
89
90
|
|
|
90
|
-
const filenames =
|
|
91
|
+
const filenames = globSync(opt.inputPatterns!, {
|
|
91
92
|
cwd: opt.baseDir,
|
|
92
93
|
dot: opt.dotfiles,
|
|
93
94
|
})
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Ajv from 'ajv'
|
|
2
|
-
|
|
3
|
-
import fastGlob from 'fast-glob'
|
|
2
|
+
export { glob, globSync } from 'tinyglobby'
|
|
4
3
|
import type {
|
|
5
4
|
AlternativesSchema,
|
|
6
5
|
AnySchema,
|
|
@@ -91,7 +90,6 @@ export type {
|
|
|
91
90
|
BinarySchema,
|
|
92
91
|
BooleanSchema,
|
|
93
92
|
DateSchema,
|
|
94
|
-
FastGlobOptions,
|
|
95
93
|
FunctionSchema,
|
|
96
94
|
ObjectSchema,
|
|
97
95
|
ValidationErrorItem,
|
|
@@ -100,4 +98,4 @@ export type {
|
|
|
100
98
|
// StringSchema,
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
export { Ajv
|
|
101
|
+
export { Ajv }
|
package/src/log/log.util.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib'
|
|
4
|
+
import { globSync } from 'tinyglobby'
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js'
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js'
|
|
6
7
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js'
|
|
7
8
|
|
|
8
9
|
export interface DecryptCLIOptions {
|
|
@@ -34,7 +35,7 @@ export function secretsDecrypt(
|
|
|
34
35
|
// If `file` is provided - only this one file is used
|
|
35
36
|
const patterns = file ? [file] : dir.map(d => `${d}/**/*.enc`)
|
|
36
37
|
|
|
37
|
-
const filenames =
|
|
38
|
+
const filenames = globSync(patterns)
|
|
38
39
|
|
|
39
40
|
filenames.forEach(filename => {
|
|
40
41
|
let plainFilename: string
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib'
|
|
4
|
+
import { globSync } from 'tinyglobby'
|
|
4
5
|
import { dimGrey, yellow } from '../colors/colors.js'
|
|
5
|
-
import {
|
|
6
|
+
import { fs2 } from '../fs/fs2.js'
|
|
6
7
|
import { encryptObject, encryptRandomIVBuffer } from '../security/crypto.util.js'
|
|
7
8
|
|
|
8
9
|
export interface EncryptCLIOptions {
|
|
@@ -30,7 +31,7 @@ export function secretsEncrypt(
|
|
|
30
31
|
...pattern,
|
|
31
32
|
`!**/*.enc`, // excluding already encoded
|
|
32
33
|
]
|
|
33
|
-
const filenames =
|
|
34
|
+
const filenames = globSync(patterns)
|
|
34
35
|
let encFilename: string
|
|
35
36
|
|
|
36
37
|
filenames.forEach(filename => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JsonSchema } from '@naturalcycles/js-lib'
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { GlobOptions } from 'tinyglobby'
|
|
3
|
+
import { globSync } from 'tinyglobby'
|
|
4
|
+
import { fs2 } from '../../fs/fs2.js'
|
|
4
5
|
import type { AjvSchemaCfg } from './ajvSchema.js'
|
|
5
6
|
import { AjvSchema } from './ajvSchema.js'
|
|
6
7
|
|
|
@@ -12,8 +13,11 @@ import { AjvSchema } from './ajvSchema.js'
|
|
|
12
13
|
*
|
|
13
14
|
* @experimental
|
|
14
15
|
*/
|
|
15
|
-
export function readJsonSchemas(
|
|
16
|
-
|
|
16
|
+
export function readJsonSchemas(
|
|
17
|
+
patterns: string | string[],
|
|
18
|
+
opt?: Omit<GlobOptions, 'patterns'>,
|
|
19
|
+
): JsonSchema[] {
|
|
20
|
+
return globSync(patterns, opt).map(fileName => fs2.readJson(fileName))
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
JsonSchemaAnyBuilder,
|
|
7
7
|
} from '@naturalcycles/js-lib'
|
|
8
8
|
import type { Ajv, ValidateFunction } from 'ajv'
|
|
9
|
-
import {
|
|
9
|
+
import { fs2 } from '../../fs/fs2.js'
|
|
10
|
+
import { _inspect } from '../../string/inspect.js'
|
|
11
|
+
import { requireFileToExist } from '../../util/env.util.js'
|
|
10
12
|
import { AjvValidationError } from './ajvValidationError.js'
|
|
11
13
|
import { getAjv } from './getAjv.js'
|
|
12
14
|
|