@naturalcycles/nodejs-lib 14.2.1 → 14.3.1
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/generate-build-info.js +0 -0
- package/dist/bin/json2env.js +0 -0
- package/dist/bin/kpy.js +0 -0
- package/dist/bin/secrets-decrypt.js +0 -0
- package/dist/bin/secrets-encrypt.js +0 -0
- package/dist/bin/secrets-gen-key.js +0 -0
- package/dist/bin/slack-this.js +0 -0
- package/dist/fs/fs2.d.ts +1 -0
- package/dist/fs/fs2.js +6 -2
- package/dist/util/env.util.d.ts +3 -0
- package/dist/util/env.util.js +5 -4
- package/dist/validation/ajv/ajvSchema.js +1 -2
- package/package.json +22 -29
- package/src/bin/generate-build-info.ts +0 -0
- package/src/bin/json2env.ts +0 -0
- package/src/fs/fs2.ts +7 -2
- package/src/util/env.util.ts +5 -4
- package/src/validation/ajv/ajvSchema.ts +1 -2
|
File without changes
|
package/dist/bin/json2env.js
CHANGED
|
File without changes
|
package/dist/bin/kpy.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/bin/slack-this.js
CHANGED
|
File without changes
|
package/dist/fs/fs2.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ declare class FS2 {
|
|
|
41
41
|
outputFileAsync(filePath: string, data: string | Buffer): Promise<void>;
|
|
42
42
|
pathExists(filePath: string): boolean;
|
|
43
43
|
pathExistsAsync(filePath: string): Promise<boolean>;
|
|
44
|
+
requireFileToExist(filePath: string): void;
|
|
44
45
|
ensureDir(dirPath: string): void;
|
|
45
46
|
ensureDirAsync(dirPath: string): Promise<void>;
|
|
46
47
|
ensureFile(filePath: string): void;
|
package/dist/fs/fs2.js
CHANGED
|
@@ -21,7 +21,6 @@ import { _isTruthy, _jsonParse } from '@naturalcycles/js-lib';
|
|
|
21
21
|
import yaml from 'js-yaml';
|
|
22
22
|
import { transformToNDJson } from '../stream/ndjson/transformToNDJson.js';
|
|
23
23
|
import { transformSplitOnNewline } from '../stream/transform/transformSplit.js';
|
|
24
|
-
import { requireFileToExist } from '../util/env.util.js';
|
|
25
24
|
/**
|
|
26
25
|
* fs2 conveniently groups filesystem functions together.
|
|
27
26
|
* Supposed to be almost a drop-in replacement for these things together:
|
|
@@ -137,6 +136,11 @@ class FS2 {
|
|
|
137
136
|
return false;
|
|
138
137
|
}
|
|
139
138
|
}
|
|
139
|
+
requireFileToExist(filePath) {
|
|
140
|
+
if (!fs.existsSync(filePath)) {
|
|
141
|
+
throw new Error(`Required file should exist: ${filePath}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
140
144
|
ensureDir(dirPath) {
|
|
141
145
|
fs.mkdirSync(dirPath, {
|
|
142
146
|
mode: 0o777,
|
|
@@ -303,7 +307,7 @@ class FS2 {
|
|
|
303
307
|
])
|
|
304
308
|
*/
|
|
305
309
|
createReadStreamAsNDJSON(inputPath) {
|
|
306
|
-
requireFileToExist(inputPath);
|
|
310
|
+
this.requireFileToExist(inputPath);
|
|
307
311
|
let stream = fs
|
|
308
312
|
.createReadStream(inputPath, {
|
|
309
313
|
highWaterMark: 64 * 1024, // no observed speedup
|
package/dist/util/env.util.d.ts
CHANGED
|
@@ -10,4 +10,7 @@ import type { ValuesOf } from '@naturalcycles/js-lib';
|
|
|
10
10
|
export declare function requireEnvKeys<T extends readonly string[]>(...keys: T): {
|
|
11
11
|
[k in ValuesOf<T>]: string;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated use fs2.requireFileToExist
|
|
15
|
+
*/
|
|
13
16
|
export declare function requireFileToExist(filePath: string): void;
|
package/dist/util/env.util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'dotenv/config'; // ensure .env is read before requiring keys
|
|
2
|
-
import {
|
|
2
|
+
import { fs2 } from '../fs/fs2.js';
|
|
3
3
|
/**
|
|
4
4
|
* @example
|
|
5
5
|
*
|
|
@@ -17,8 +17,9 @@ export function requireEnvKeys(...keys) {
|
|
|
17
17
|
return r;
|
|
18
18
|
}, {});
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated use fs2.requireFileToExist
|
|
22
|
+
*/
|
|
20
23
|
export function requireFileToExist(filePath) {
|
|
21
|
-
|
|
22
|
-
throw new Error(`Required file should exist: ${filePath}`);
|
|
23
|
-
}
|
|
24
|
+
fs2.requireFileToExist(filePath);
|
|
24
25
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { _filterNullishValues, _isObject, _substringBefore, JsonSchemaAnyBuilder, } from '@naturalcycles/js-lib';
|
|
2
2
|
import { fs2 } from '../../fs/fs2.js';
|
|
3
3
|
import { _inspect } from '../../string/inspect.js';
|
|
4
|
-
import { requireFileToExist } from '../../util/env.util.js';
|
|
5
4
|
import { AjvValidationError } from './ajvValidationError.js';
|
|
6
5
|
import { getAjv } from './getAjv.js';
|
|
7
6
|
/**
|
|
@@ -58,7 +57,7 @@ export class AjvSchema {
|
|
|
58
57
|
* Convenient method that just does fs.readFileSync for you.
|
|
59
58
|
*/
|
|
60
59
|
static readJsonSync(filePath, cfg = {}) {
|
|
61
|
-
requireFileToExist(filePath);
|
|
60
|
+
fs2.requireFileToExist(filePath);
|
|
62
61
|
const schema = fs2.readJson(filePath);
|
|
63
62
|
return new AjvSchema(schema, cfg);
|
|
64
63
|
}
|
package/package.json
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "14.
|
|
5
|
-
"scripts": {
|
|
6
|
-
"prepare": "husky",
|
|
7
|
-
"build": "dev-lib build",
|
|
8
|
-
"test": "dev-lib test",
|
|
9
|
-
"lint": "dev-lib lint",
|
|
10
|
-
"bt": "dev-lib bt",
|
|
11
|
-
"lbt": "dev-lib lbt",
|
|
12
|
-
"docs-serve": "vuepress dev docs",
|
|
13
|
-
"docs-build": "vuepress build docs",
|
|
14
|
-
"slack-this-debug": "tsx ./src/bin/slack-this.ts --channel test --msg 'Hello slack!'",
|
|
15
|
-
"secrets-gen-key-debug": "tsx ./src/bin/secrets-gen-key.ts",
|
|
16
|
-
"secrets-encrypt-debug": "tsx ./src/bin/secrets-encrypt.ts",
|
|
17
|
-
"secrets-decrypt-debug": "tsx ./src/bin/secrets-decrypt.ts",
|
|
18
|
-
"kpy-debug": "tsx ./src/bin/kpy.ts --verbose scripts tmp/scripts",
|
|
19
|
-
"kpy-debug2": "tsx ./src/bin/kpy.ts --verbose scripts bench non-ex non-ex/** colors* tmp/scripts",
|
|
20
|
-
"kpy-debug3": "tsx ./src/bin/kpy.ts --verbose src colors csv stream non-ex non-ex/** tmp/src",
|
|
21
|
-
"json2env-debug": "tsx ./src/bin/json2env.ts ./src/test/someFile.json"
|
|
22
|
-
},
|
|
4
|
+
"version": "14.3.1",
|
|
23
5
|
"dependencies": {
|
|
24
|
-
"@naturalcycles/js-lib": "^15",
|
|
25
6
|
"@types/js-yaml": "^4",
|
|
26
7
|
"@types/jsonwebtoken": "^9",
|
|
27
8
|
"@types/yargs": "^16",
|
|
@@ -36,15 +17,11 @@
|
|
|
36
17
|
"lru-cache": "^11",
|
|
37
18
|
"through2-concurrent": "^2",
|
|
38
19
|
"tinyglobby": "^0.2",
|
|
39
|
-
"yargs": "^17"
|
|
20
|
+
"yargs": "^17",
|
|
21
|
+
"@naturalcycles/js-lib": "^15.0.0"
|
|
40
22
|
},
|
|
41
23
|
"devDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@naturalcycles/dev-lib": "^18",
|
|
44
|
-
"@types/node": "^22",
|
|
45
|
-
"@types/through2-concurrent": "^2",
|
|
46
|
-
"tsx": "^4",
|
|
47
|
-
"vitest": "^3"
|
|
24
|
+
"@types/through2-concurrent": "^2"
|
|
48
25
|
},
|
|
49
26
|
"bin": {
|
|
50
27
|
"kpy": "dist/bin/kpy.js",
|
|
@@ -70,7 +47,8 @@
|
|
|
70
47
|
},
|
|
71
48
|
"repository": {
|
|
72
49
|
"type": "git",
|
|
73
|
-
"url": "
|
|
50
|
+
"url": "git@github.com:NaturalCycles/js-lib.git",
|
|
51
|
+
"directory": "packages/nodejs-lib"
|
|
74
52
|
},
|
|
75
53
|
"engines": {
|
|
76
54
|
"node": ">=22.12.0"
|
|
@@ -81,5 +59,20 @@
|
|
|
81
59
|
"envByBranch": {
|
|
82
60
|
"master": "master",
|
|
83
61
|
"*": "branch"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "dev-lib build",
|
|
65
|
+
"test": "dev-lib test",
|
|
66
|
+
"lint": "dev-lib lint",
|
|
67
|
+
"bt": "dev-lib bt",
|
|
68
|
+
"lbt": "dev-lib lbt",
|
|
69
|
+
"slack-this-debug": "tsx ./src/bin/slack-this.ts --channel test --msg 'Hello slack!'",
|
|
70
|
+
"secrets-gen-key-debug": "tsx ./src/bin/secrets-gen-key.ts",
|
|
71
|
+
"secrets-encrypt-debug": "tsx ./src/bin/secrets-encrypt.ts",
|
|
72
|
+
"secrets-decrypt-debug": "tsx ./src/bin/secrets-decrypt.ts",
|
|
73
|
+
"kpy-debug": "tsx ./src/bin/kpy.ts --verbose scripts tmp/scripts",
|
|
74
|
+
"kpy-debug2": "tsx ./src/bin/kpy.ts --verbose scripts bench non-ex non-ex/** colors* tmp/scripts",
|
|
75
|
+
"kpy-debug3": "tsx ./src/bin/kpy.ts --verbose src colors csv stream non-ex non-ex/** tmp/src",
|
|
76
|
+
"json2env-debug": "tsx ./src/bin/json2env.ts ./src/test/someFile.json"
|
|
84
77
|
}
|
|
85
|
-
}
|
|
78
|
+
}
|
|
File without changes
|
package/src/bin/json2env.ts
CHANGED
|
File without changes
|
package/src/fs/fs2.ts
CHANGED
|
@@ -25,7 +25,6 @@ import yaml from 'js-yaml'
|
|
|
25
25
|
import { transformToNDJson } from '../stream/ndjson/transformToNDJson.js'
|
|
26
26
|
import type { ReadableTyped, TransformTyped } from '../stream/stream.model.js'
|
|
27
27
|
import { transformSplitOnNewline } from '../stream/transform/transformSplit.js'
|
|
28
|
-
import { requireFileToExist } from '../util/env.util.js'
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* fs2 conveniently groups filesystem functions together.
|
|
@@ -168,6 +167,12 @@ class FS2 {
|
|
|
168
167
|
}
|
|
169
168
|
}
|
|
170
169
|
|
|
170
|
+
requireFileToExist(filePath: string): void {
|
|
171
|
+
if (!fs.existsSync(filePath)) {
|
|
172
|
+
throw new Error(`Required file should exist: ${filePath}`)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
171
176
|
ensureDir(dirPath: string): void {
|
|
172
177
|
fs.mkdirSync(dirPath, {
|
|
173
178
|
mode: 0o777,
|
|
@@ -350,7 +355,7 @@ class FS2 {
|
|
|
350
355
|
])
|
|
351
356
|
*/
|
|
352
357
|
createReadStreamAsNDJSON<ROW = any>(inputPath: string): ReadableTyped<ROW> {
|
|
353
|
-
requireFileToExist(inputPath)
|
|
358
|
+
this.requireFileToExist(inputPath)
|
|
354
359
|
|
|
355
360
|
let stream: ReadableTyped<ROW> = fs
|
|
356
361
|
.createReadStream(inputPath, {
|
package/src/util/env.util.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'dotenv/config' // ensure .env is read before requiring keys
|
|
2
|
-
import { existsSync } from 'node:fs'
|
|
3
2
|
import type { ValuesOf } from '@naturalcycles/js-lib'
|
|
3
|
+
import { fs2 } from '../fs/fs2.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @example
|
|
@@ -24,8 +24,9 @@ export function requireEnvKeys<T extends readonly string[]>(
|
|
|
24
24
|
)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use fs2.requireFileToExist
|
|
29
|
+
*/
|
|
27
30
|
export function requireFileToExist(filePath: string): void {
|
|
28
|
-
|
|
29
|
-
throw new Error(`Required file should exist: ${filePath}`)
|
|
30
|
-
}
|
|
31
|
+
fs2.requireFileToExist(filePath)
|
|
31
32
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
import type { Ajv, ValidateFunction } from 'ajv'
|
|
9
9
|
import { fs2 } from '../../fs/fs2.js'
|
|
10
10
|
import { _inspect } from '../../string/inspect.js'
|
|
11
|
-
import { requireFileToExist } from '../../util/env.util.js'
|
|
12
11
|
import { AjvValidationError } from './ajvValidationError.js'
|
|
13
12
|
import { getAjv } from './getAjv.js'
|
|
14
13
|
|
|
@@ -133,7 +132,7 @@ export class AjvSchema<T = unknown> {
|
|
|
133
132
|
filePath: string,
|
|
134
133
|
cfg: Partial<AjvSchemaCfg> = {},
|
|
135
134
|
): AjvSchema<T> {
|
|
136
|
-
requireFileToExist(filePath)
|
|
135
|
+
fs2.requireFileToExist(filePath)
|
|
137
136
|
const schema = fs2.readJson<JsonSchema<T>>(filePath)
|
|
138
137
|
return new AjvSchema<T>(schema, cfg)
|
|
139
138
|
}
|