@naturalcycles/nodejs-lib 15.97.5 → 15.99.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/secrets-decrypt.d.ts +1 -1
- package/dist/bin/secrets-decrypt.js +0 -1
- package/dist/bin/secrets-encrypt.d.ts +1 -1
- package/dist/bin/secrets-encrypt.js +0 -1
- package/dist/colors/colors.d.ts +26 -26
- package/dist/colors/colors.js +28 -28
- package/dist/fs/fs2.js +0 -1
- package/dist/fs/yaml2.d.ts +6 -5
- package/dist/fs/yaml2.js +7 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/node.util.d.ts +4 -0
- package/dist/node.util.js +16 -0
- package/dist/script/runScript.d.ts +0 -1
- package/dist/script/runScript.js +2 -1
- package/dist/secret/secrets-decrypt.util.js +1 -2
- package/dist/security/secret.util.js +1 -1
- package/dist/validation/ajv/getAjv.js +0 -1
- package/dist/validation/ajv/jSchema.js +2 -4
- package/dist/yargs/yargs.util.js +1 -1
- package/package.json +3 -5
- package/src/bin/secrets-decrypt.ts +0 -1
- package/src/bin/secrets-encrypt.ts +0 -1
- package/src/colors/colors.ts +28 -28
- package/src/fs/fs2.ts +0 -1
- package/src/fs/yaml2.ts +24 -12
- package/src/index.ts +1 -0
- package/src/node.util.ts +16 -0
- package/src/script/runScript.ts +3 -1
- package/src/secret/secrets-decrypt.util.ts +1 -2
- package/src/security/secret.util.ts +1 -1
- package/src/stream/stream.model.ts +0 -3
- package/src/validation/ajv/getAjv.ts +0 -1
- package/src/validation/ajv/jSchema.ts +2 -5
- package/src/yargs/yargs.util.ts +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
export {};
|
package/dist/colors/colors.d.ts
CHANGED
|
@@ -4,29 +4,29 @@
|
|
|
4
4
|
* @experimental
|
|
5
5
|
*/
|
|
6
6
|
export declare const hasColors: boolean;
|
|
7
|
-
export declare const white: import("
|
|
8
|
-
export declare const dimWhite: import("
|
|
9
|
-
export declare const boldWhite: import("
|
|
10
|
-
export declare const inverseWhite: import("
|
|
11
|
-
export declare const grey: import("
|
|
12
|
-
export declare const dimGrey: import("
|
|
13
|
-
export declare const boldGrey: import("
|
|
14
|
-
export declare const yellow: import("
|
|
15
|
-
export declare const dimYellow: import("
|
|
16
|
-
export declare const boldYellow: import("
|
|
17
|
-
export declare const inverseYellow: import("
|
|
18
|
-
export declare const green: import("
|
|
19
|
-
export declare const dimGreen: import("
|
|
20
|
-
export declare const boldGreen: import("
|
|
21
|
-
export declare const red: import("
|
|
22
|
-
export declare const dimRed: import("
|
|
23
|
-
export declare const boldRed: import("
|
|
24
|
-
export declare const blue: import("
|
|
25
|
-
export declare const dimBlue: import("
|
|
26
|
-
export declare const boldBlue: import("
|
|
27
|
-
export declare const magenta: import("
|
|
28
|
-
export declare const dimMagenta: import("
|
|
29
|
-
export declare const boldMagenta: import("
|
|
30
|
-
export declare const cyan: import("
|
|
31
|
-
export declare const dimCyan: import("
|
|
32
|
-
export declare const boldCyan: import("
|
|
7
|
+
export declare const white: import("ansis").Ansis;
|
|
8
|
+
export declare const dimWhite: import("ansis").Ansis;
|
|
9
|
+
export declare const boldWhite: import("ansis").Ansis;
|
|
10
|
+
export declare const inverseWhite: import("ansis").Ansis;
|
|
11
|
+
export declare const grey: import("ansis").Ansis;
|
|
12
|
+
export declare const dimGrey: import("ansis").Ansis;
|
|
13
|
+
export declare const boldGrey: import("ansis").Ansis;
|
|
14
|
+
export declare const yellow: import("ansis").Ansis;
|
|
15
|
+
export declare const dimYellow: import("ansis").Ansis;
|
|
16
|
+
export declare const boldYellow: import("ansis").Ansis;
|
|
17
|
+
export declare const inverseYellow: import("ansis").Ansis;
|
|
18
|
+
export declare const green: import("ansis").Ansis;
|
|
19
|
+
export declare const dimGreen: import("ansis").Ansis;
|
|
20
|
+
export declare const boldGreen: import("ansis").Ansis;
|
|
21
|
+
export declare const red: import("ansis").Ansis;
|
|
22
|
+
export declare const dimRed: import("ansis").Ansis;
|
|
23
|
+
export declare const boldRed: import("ansis").Ansis;
|
|
24
|
+
export declare const blue: import("ansis").Ansis;
|
|
25
|
+
export declare const dimBlue: import("ansis").Ansis;
|
|
26
|
+
export declare const boldBlue: import("ansis").Ansis;
|
|
27
|
+
export declare const magenta: import("ansis").Ansis;
|
|
28
|
+
export declare const dimMagenta: import("ansis").Ansis;
|
|
29
|
+
export declare const boldMagenta: import("ansis").Ansis;
|
|
30
|
+
export declare const cyan: import("ansis").Ansis;
|
|
31
|
+
export declare const dimCyan: import("ansis").Ansis;
|
|
32
|
+
export declare const boldCyan: import("ansis").Ansis;
|
package/dist/colors/colors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import tty from 'node:tty';
|
|
2
|
-
import
|
|
2
|
+
import ansis from 'ansis';
|
|
3
3
|
/**
|
|
4
4
|
* Based on: https://github.com/sindresorhus/yoctocolors/pull/5
|
|
5
5
|
*
|
|
@@ -8,31 +8,31 @@ import chalk from 'chalk';
|
|
|
8
8
|
export const hasColors = !process.env['NO_COLOR'] && tty.WriteStream.prototype.hasColors();
|
|
9
9
|
// The point of re-exporting is:
|
|
10
10
|
// 1. Fix typings to allow to pass `number` (very common case)
|
|
11
|
-
// 2. Easier/shorter to import, rather than from '
|
|
11
|
+
// 2. Easier/shorter to import, rather than from 'ansis'
|
|
12
12
|
// export type ColorFn = (...args: (string | number)[]) => string
|
|
13
|
-
export const white =
|
|
14
|
-
export const dimWhite =
|
|
15
|
-
export const boldWhite =
|
|
16
|
-
export const inverseWhite =
|
|
17
|
-
export const grey =
|
|
18
|
-
export const dimGrey =
|
|
19
|
-
export const boldGrey =
|
|
20
|
-
export const yellow =
|
|
21
|
-
export const dimYellow =
|
|
22
|
-
export const boldYellow =
|
|
23
|
-
export const inverseYellow =
|
|
24
|
-
export const green =
|
|
25
|
-
export const dimGreen =
|
|
26
|
-
export const boldGreen =
|
|
27
|
-
export const red =
|
|
28
|
-
export const dimRed =
|
|
29
|
-
export const boldRed =
|
|
30
|
-
export const blue =
|
|
31
|
-
export const dimBlue =
|
|
32
|
-
export const boldBlue =
|
|
33
|
-
export const magenta =
|
|
34
|
-
export const dimMagenta =
|
|
35
|
-
export const boldMagenta =
|
|
36
|
-
export const cyan =
|
|
37
|
-
export const dimCyan =
|
|
38
|
-
export const boldCyan =
|
|
13
|
+
export const white = ansis.white;
|
|
14
|
+
export const dimWhite = ansis.dim.white;
|
|
15
|
+
export const boldWhite = ansis.bold.white;
|
|
16
|
+
export const inverseWhite = ansis.inverse.white;
|
|
17
|
+
export const grey = ansis.gray;
|
|
18
|
+
export const dimGrey = ansis.dim.gray;
|
|
19
|
+
export const boldGrey = ansis.bold.gray;
|
|
20
|
+
export const yellow = ansis.yellow;
|
|
21
|
+
export const dimYellow = ansis.dim.yellow;
|
|
22
|
+
export const boldYellow = ansis.bold.yellow;
|
|
23
|
+
export const inverseYellow = ansis.inverse.yellow;
|
|
24
|
+
export const green = ansis.green;
|
|
25
|
+
export const dimGreen = ansis.dim.green;
|
|
26
|
+
export const boldGreen = ansis.bold.green;
|
|
27
|
+
export const red = ansis.red;
|
|
28
|
+
export const dimRed = ansis.dim.red;
|
|
29
|
+
export const boldRed = ansis.bold.red;
|
|
30
|
+
export const blue = ansis.blue;
|
|
31
|
+
export const dimBlue = ansis.dim.blue;
|
|
32
|
+
export const boldBlue = ansis.bold.blue;
|
|
33
|
+
export const magenta = ansis.magenta;
|
|
34
|
+
export const dimMagenta = ansis.dim.magenta;
|
|
35
|
+
export const boldMagenta = ansis.bold.magenta;
|
|
36
|
+
export const cyan = ansis.cyan;
|
|
37
|
+
export const dimCyan = ansis.dim.cyan;
|
|
38
|
+
export const boldCyan = ansis.bold.cyan;
|
package/dist/fs/fs2.js
CHANGED
package/dist/fs/yaml2.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToStringOptions } from 'yaml';
|
|
2
|
+
export type YamlStringifyOptions = DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions;
|
|
2
3
|
declare class Yaml2 {
|
|
3
4
|
readYaml<T = unknown>(filePath: string): T;
|
|
4
5
|
readYamlAsync<T = unknown>(filePath: string): Promise<T>;
|
|
5
|
-
writeYaml(filePath: string, data: any, opt?:
|
|
6
|
-
writeYamlAsync(filePath: string, data: any, opt?:
|
|
7
|
-
outputYaml(filePath: string, data: any, opt?:
|
|
8
|
-
outputYamlAsync(filePath: string, data: any, opt?:
|
|
6
|
+
writeYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void;
|
|
7
|
+
writeYamlAsync(filePath: string, data: any, opt?: YamlStringifyOptions): Promise<void>;
|
|
8
|
+
outputYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void;
|
|
9
|
+
outputYamlAsync(filePath: string, data: any, opt?: YamlStringifyOptions): Promise<void>;
|
|
9
10
|
}
|
|
10
11
|
export declare const yaml2: Yaml2;
|
|
11
12
|
export {};
|
package/dist/fs/yaml2.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import fsp from 'node:fs/promises';
|
|
3
|
-
import
|
|
3
|
+
import { parse, stringify } from 'yaml';
|
|
4
4
|
import { fs2 } from './fs2.js';
|
|
5
5
|
class Yaml2 {
|
|
6
6
|
readYaml(filePath) {
|
|
7
|
-
return
|
|
7
|
+
return parse(fs.readFileSync(filePath, 'utf8'));
|
|
8
8
|
}
|
|
9
9
|
async readYamlAsync(filePath) {
|
|
10
|
-
return
|
|
10
|
+
return parse(await fsp.readFile(filePath, 'utf8'));
|
|
11
11
|
}
|
|
12
12
|
writeYaml(filePath, data, opt) {
|
|
13
|
-
const str =
|
|
13
|
+
const str = stringify(data, opt);
|
|
14
14
|
fs.writeFileSync(filePath, str);
|
|
15
15
|
}
|
|
16
16
|
async writeYamlAsync(filePath, data, opt) {
|
|
17
|
-
const str =
|
|
17
|
+
const str = stringify(data, opt);
|
|
18
18
|
await fsp.writeFile(filePath, str);
|
|
19
19
|
}
|
|
20
20
|
outputYaml(filePath, data, opt) {
|
|
21
|
-
const str =
|
|
21
|
+
const str = stringify(data, opt);
|
|
22
22
|
fs2.outputFile(filePath, str);
|
|
23
23
|
}
|
|
24
24
|
async outputYamlAsync(filePath, data, opt) {
|
|
25
|
-
const str =
|
|
25
|
+
const str = stringify(data, opt);
|
|
26
26
|
await fs2.outputFileAsync(filePath, str);
|
|
27
27
|
}
|
|
28
28
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ 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 './node.util.js';
|
|
5
6
|
export * from './security/crypto.util.js';
|
|
6
7
|
export * from './security/hash.util.js';
|
|
7
8
|
export * from './security/id.util.js';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ 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 './node.util.js';
|
|
5
6
|
export * from './security/crypto.util.js';
|
|
6
7
|
export * from './security/hash.util.js';
|
|
7
8
|
export * from './security/id.util.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if load was successful
|
|
3
|
+
*/
|
|
4
|
+
export function loadEnvFileIfExists(path = '.env') {
|
|
5
|
+
try {
|
|
6
|
+
process.loadEnvFile(path);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
if (err.code === 'ENOENT') {
|
|
11
|
+
// gracefully ignore that the file does not exist
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/script/runScript.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import 'dotenv/config';
|
|
2
1
|
import os from 'node:os';
|
|
3
2
|
import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js';
|
|
4
3
|
import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string/stringify.js';
|
|
5
4
|
import { dimGrey } from '../colors/colors.js';
|
|
5
|
+
import { loadEnvFileIfExists } from '../node.util.js';
|
|
6
6
|
import { inspectStringifyFn } from '../string/inspect.js';
|
|
7
|
+
loadEnvFileIfExists();
|
|
7
8
|
const { DEBUG_RUN_SCRIPT } = process.env;
|
|
8
9
|
/**
|
|
9
10
|
* Use it in your top-level scripts like this:
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
1
|
+
import fs, { globSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
4
|
-
import { globSync } from 'tinyglobby';
|
|
5
4
|
import { dimGrey, yellow } from '../colors/colors.js';
|
|
6
5
|
import { fs2 } from '../fs/fs2.js';
|
|
7
6
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js';
|
|
@@ -11,7 +11,7 @@ const secretMap = {};
|
|
|
11
11
|
* Does NOT delete previous secrets from secretMap.
|
|
12
12
|
*/
|
|
13
13
|
export function loadSecretsFromEnv() {
|
|
14
|
-
//
|
|
14
|
+
// loadEnvFileIfExists() // ensure .env is loaded
|
|
15
15
|
const secrets = {};
|
|
16
16
|
Object.keys(process.env)
|
|
17
17
|
.filter(k => k.toUpperCase().startsWith('SECRET_'))
|
|
@@ -4,7 +4,6 @@ import { _deepCopy, _mapObject, Set2 } from '@naturalcycles/js-lib/object';
|
|
|
4
4
|
import { _substringAfterLast } from '@naturalcycles/js-lib/string';
|
|
5
5
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
6
6
|
import { validTLDs } from '../tlds.js';
|
|
7
|
-
/* eslint-disable @typescript-eslint/prefer-string-starts-ends-with */
|
|
8
7
|
// oxlint-disable unicorn/prefer-code-point
|
|
9
8
|
const AJV_OPTIONS = {
|
|
10
9
|
removeAdditional: true,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable id-denylist */
|
|
2
|
-
// oxlint-disable max-lines
|
|
3
1
|
import { _isObject, _isUndefined, _numberEnumValues, _stringEnumValues, getEnumType, } from '@naturalcycles/js-lib';
|
|
4
2
|
import { _uniq } from '@naturalcycles/js-lib/array';
|
|
5
3
|
import { _assert, _try } from '@naturalcycles/js-lib/error';
|
|
@@ -822,7 +820,7 @@ export class JObject extends JBuilder {
|
|
|
822
820
|
/**
|
|
823
821
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
824
822
|
*/
|
|
825
|
-
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
823
|
+
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
826
824
|
dbEntity() {
|
|
827
825
|
return this.extend({
|
|
828
826
|
id: j.string(),
|
|
@@ -872,7 +870,7 @@ export class JObjectInfer extends JBuilder {
|
|
|
872
870
|
/**
|
|
873
871
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
874
872
|
*/
|
|
875
|
-
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
873
|
+
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
876
874
|
dbEntity() {
|
|
877
875
|
return this.extend({
|
|
878
876
|
id: j.string(),
|
package/dist/yargs/yargs.util.js
CHANGED
|
@@ -5,7 +5,7 @@ import { hideBin } from 'yargs/helpers';
|
|
|
5
5
|
* Quick yargs helper to make it work in esm.
|
|
6
6
|
* It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
|
|
7
7
|
*/
|
|
8
|
-
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
8
|
+
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
9
9
|
export function _yargs() {
|
|
10
10
|
return yargs(hideBin(process.argv));
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.99.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@standard-schema/spec": "^1",
|
|
8
|
-
"@types/js-yaml": "^4",
|
|
9
8
|
"@types/jsonwebtoken": "^9",
|
|
10
9
|
"@types/yargs": "^16",
|
|
11
10
|
"ajv": "^8",
|
|
12
|
-
"
|
|
13
|
-
"dotenv": "^17",
|
|
14
|
-
"js-yaml": "^4",
|
|
11
|
+
"ansis": "^4",
|
|
15
12
|
"jsonwebtoken": "^9",
|
|
16
13
|
"lru-cache": "^11",
|
|
17
14
|
"tinyglobby": "^0.2",
|
|
18
15
|
"tslib": "^2",
|
|
16
|
+
"yaml": "^2",
|
|
19
17
|
"yargs": "^18"
|
|
20
18
|
},
|
|
21
19
|
"devDependencies": {
|
package/src/colors/colors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import tty from 'node:tty'
|
|
2
|
-
import
|
|
2
|
+
import ansis from 'ansis'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Based on: https://github.com/sindresorhus/yoctocolors/pull/5
|
|
@@ -10,32 +10,32 @@ export const hasColors = !process.env['NO_COLOR'] && tty.WriteStream.prototype.h
|
|
|
10
10
|
|
|
11
11
|
// The point of re-exporting is:
|
|
12
12
|
// 1. Fix typings to allow to pass `number` (very common case)
|
|
13
|
-
// 2. Easier/shorter to import, rather than from '
|
|
13
|
+
// 2. Easier/shorter to import, rather than from 'ansis'
|
|
14
14
|
// export type ColorFn = (...args: (string | number)[]) => string
|
|
15
15
|
|
|
16
|
-
export const white =
|
|
17
|
-
export const dimWhite =
|
|
18
|
-
export const boldWhite =
|
|
19
|
-
export const inverseWhite =
|
|
20
|
-
export const grey =
|
|
21
|
-
export const dimGrey =
|
|
22
|
-
export const boldGrey =
|
|
23
|
-
export const yellow =
|
|
24
|
-
export const dimYellow =
|
|
25
|
-
export const boldYellow =
|
|
26
|
-
export const inverseYellow =
|
|
27
|
-
export const green =
|
|
28
|
-
export const dimGreen =
|
|
29
|
-
export const boldGreen =
|
|
30
|
-
export const red =
|
|
31
|
-
export const dimRed =
|
|
32
|
-
export const boldRed =
|
|
33
|
-
export const blue =
|
|
34
|
-
export const dimBlue =
|
|
35
|
-
export const boldBlue =
|
|
36
|
-
export const magenta =
|
|
37
|
-
export const dimMagenta =
|
|
38
|
-
export const boldMagenta =
|
|
39
|
-
export const cyan =
|
|
40
|
-
export const dimCyan =
|
|
41
|
-
export const boldCyan =
|
|
16
|
+
export const white = ansis.white
|
|
17
|
+
export const dimWhite = ansis.dim.white
|
|
18
|
+
export const boldWhite = ansis.bold.white
|
|
19
|
+
export const inverseWhite = ansis.inverse.white
|
|
20
|
+
export const grey = ansis.gray
|
|
21
|
+
export const dimGrey = ansis.dim.gray
|
|
22
|
+
export const boldGrey = ansis.bold.gray
|
|
23
|
+
export const yellow = ansis.yellow
|
|
24
|
+
export const dimYellow = ansis.dim.yellow
|
|
25
|
+
export const boldYellow = ansis.bold.yellow
|
|
26
|
+
export const inverseYellow = ansis.inverse.yellow
|
|
27
|
+
export const green = ansis.green
|
|
28
|
+
export const dimGreen = ansis.dim.green
|
|
29
|
+
export const boldGreen = ansis.bold.green
|
|
30
|
+
export const red = ansis.red
|
|
31
|
+
export const dimRed = ansis.dim.red
|
|
32
|
+
export const boldRed = ansis.bold.red
|
|
33
|
+
export const blue = ansis.blue
|
|
34
|
+
export const dimBlue = ansis.dim.blue
|
|
35
|
+
export const boldBlue = ansis.bold.blue
|
|
36
|
+
export const magenta = ansis.magenta
|
|
37
|
+
export const dimMagenta = ansis.dim.magenta
|
|
38
|
+
export const boldMagenta = ansis.bold.magenta
|
|
39
|
+
export const cyan = ansis.cyan
|
|
40
|
+
export const dimCyan = ansis.dim.cyan
|
|
41
|
+
export const boldCyan = ansis.bold.cyan
|
package/src/fs/fs2.ts
CHANGED
package/src/fs/yaml2.ts
CHANGED
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import fsp from 'node:fs/promises'
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
CreateNodeOptions,
|
|
5
|
+
DocumentOptions,
|
|
6
|
+
ParseOptions,
|
|
7
|
+
SchemaOptions,
|
|
8
|
+
ToStringOptions,
|
|
9
|
+
} from 'yaml'
|
|
10
|
+
import { parse, stringify } from 'yaml'
|
|
5
11
|
import { fs2 } from './fs2.js'
|
|
6
12
|
|
|
13
|
+
export type YamlStringifyOptions = DocumentOptions &
|
|
14
|
+
SchemaOptions &
|
|
15
|
+
ParseOptions &
|
|
16
|
+
CreateNodeOptions &
|
|
17
|
+
ToStringOptions
|
|
18
|
+
|
|
7
19
|
class Yaml2 {
|
|
8
20
|
readYaml<T = unknown>(filePath: string): T {
|
|
9
|
-
return
|
|
21
|
+
return parse(fs.readFileSync(filePath, 'utf8')) as T
|
|
10
22
|
}
|
|
11
23
|
|
|
12
24
|
async readYamlAsync<T = unknown>(filePath: string): Promise<T> {
|
|
13
|
-
return
|
|
25
|
+
return parse(await fsp.readFile(filePath, 'utf8')) as T
|
|
14
26
|
}
|
|
15
27
|
|
|
16
|
-
writeYaml(filePath: string, data: any, opt?:
|
|
17
|
-
const str =
|
|
28
|
+
writeYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void {
|
|
29
|
+
const str = stringify(data, opt)
|
|
18
30
|
fs.writeFileSync(filePath, str)
|
|
19
31
|
}
|
|
20
32
|
|
|
21
|
-
async writeYamlAsync(filePath: string, data: any, opt?:
|
|
22
|
-
const str =
|
|
33
|
+
async writeYamlAsync(filePath: string, data: any, opt?: YamlStringifyOptions): Promise<void> {
|
|
34
|
+
const str = stringify(data, opt)
|
|
23
35
|
await fsp.writeFile(filePath, str)
|
|
24
36
|
}
|
|
25
37
|
|
|
26
|
-
outputYaml(filePath: string, data: any, opt?:
|
|
27
|
-
const str =
|
|
38
|
+
outputYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void {
|
|
39
|
+
const str = stringify(data, opt)
|
|
28
40
|
fs2.outputFile(filePath, str)
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
async outputYamlAsync(filePath: string, data: any, opt?:
|
|
32
|
-
const str =
|
|
43
|
+
async outputYamlAsync(filePath: string, data: any, opt?: YamlStringifyOptions): Promise<void> {
|
|
44
|
+
const str = stringify(data, opt)
|
|
33
45
|
await fs2.outputFileAsync(filePath, str)
|
|
34
46
|
}
|
|
35
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ 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 './node.util.js'
|
|
5
6
|
export * from './security/crypto.util.js'
|
|
6
7
|
export * from './security/hash.util.js'
|
|
7
8
|
export * from './security/id.util.js'
|
package/src/node.util.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if load was successful
|
|
3
|
+
*/
|
|
4
|
+
export function loadEnvFileIfExists(path = '.env'): boolean {
|
|
5
|
+
try {
|
|
6
|
+
process.loadEnvFile(path)
|
|
7
|
+
return true
|
|
8
|
+
} catch (err) {
|
|
9
|
+
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
10
|
+
// gracefully ignore that the file does not exist
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
throw err
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/script/runScript.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import 'dotenv/config'
|
|
2
1
|
import os from 'node:os'
|
|
3
2
|
import type { CommonLogger } from '@naturalcycles/js-lib/log'
|
|
4
3
|
import { pDelay } from '@naturalcycles/js-lib/promise/pDelay.js'
|
|
5
4
|
import { setGlobalStringifyFunction } from '@naturalcycles/js-lib/string/stringify.js'
|
|
6
5
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
7
6
|
import { dimGrey } from '../colors/colors.js'
|
|
7
|
+
import { loadEnvFileIfExists } from '../node.util.js'
|
|
8
8
|
import { inspectStringifyFn } from '../string/inspect.js'
|
|
9
9
|
|
|
10
|
+
loadEnvFileIfExists()
|
|
11
|
+
|
|
10
12
|
export interface RunScriptOptions {
|
|
11
13
|
/**
|
|
12
14
|
* @default false
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
1
|
+
import fs, { globSync } from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
4
|
-
import { globSync } from 'tinyglobby'
|
|
5
4
|
import { dimGrey, yellow } from '../colors/colors.js'
|
|
6
5
|
import { fs2 } from '../fs/fs2.js'
|
|
7
6
|
import { decryptObject, decryptRandomIVBuffer } from '../security/crypto.util.js'
|
|
@@ -15,7 +15,7 @@ const secretMap: StringMap = {}
|
|
|
15
15
|
* Does NOT delete previous secrets from secretMap.
|
|
16
16
|
*/
|
|
17
17
|
export function loadSecretsFromEnv(): void {
|
|
18
|
-
//
|
|
18
|
+
// loadEnvFileIfExists() // ensure .env is loaded
|
|
19
19
|
|
|
20
20
|
const secrets: StringMap = {}
|
|
21
21
|
Object.keys(process.env)
|
|
@@ -50,12 +50,9 @@ export interface ReadableTyped<T = unknown> extends Readable {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// oxlint-disable no-unused-vars
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
54
53
|
export interface WritableTyped<_T> extends Writable {}
|
|
55
54
|
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
57
55
|
export interface TransformTyped<_IN = unknown, _OUT = unknown> extends Transform {}
|
|
58
|
-
// oxlint-enable
|
|
59
56
|
|
|
60
57
|
export interface TransformOptions {
|
|
61
58
|
/**
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable id-denylist */
|
|
2
|
-
// oxlint-disable max-lines
|
|
3
|
-
|
|
4
1
|
import type { ValidationFunction, ValidationFunctionResult } from '@naturalcycles/js-lib'
|
|
5
2
|
import {
|
|
6
3
|
_isObject,
|
|
@@ -1122,7 +1119,7 @@ export class JObject<OUT extends AnyObject, Opt extends boolean = false> extends
|
|
|
1122
1119
|
/**
|
|
1123
1120
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
1124
1121
|
*/
|
|
1125
|
-
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1122
|
+
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1126
1123
|
dbEntity() {
|
|
1127
1124
|
return this.extend({
|
|
1128
1125
|
id: j.string(),
|
|
@@ -1229,7 +1226,7 @@ export class JObjectInfer<
|
|
|
1229
1226
|
/**
|
|
1230
1227
|
* Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
|
|
1231
1228
|
*/
|
|
1232
|
-
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1229
|
+
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
1233
1230
|
dbEntity() {
|
|
1234
1231
|
return this.extend({
|
|
1235
1232
|
id: j.string(),
|
package/src/yargs/yargs.util.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { hideBin } from 'yargs/helpers'
|
|
|
6
6
|
* Quick yargs helper to make it work in esm.
|
|
7
7
|
* It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
|
|
8
8
|
*/
|
|
9
|
-
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
9
|
+
// oxlint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
10
10
|
export function _yargs() {
|
|
11
11
|
return yargs(hideBin(process.argv))
|
|
12
12
|
}
|