@naturalcycles/nodejs-lib 15.97.4 → 15.98.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.
@@ -4,29 +4,29 @@
4
4
  * @experimental
5
5
  */
6
6
  export declare const hasColors: boolean;
7
- export declare const white: import("chalk").ChalkInstance;
8
- export declare const dimWhite: import("chalk").ChalkInstance;
9
- export declare const boldWhite: import("chalk").ChalkInstance;
10
- export declare const inverseWhite: import("chalk").ChalkInstance;
11
- export declare const grey: import("chalk").ChalkInstance;
12
- export declare const dimGrey: import("chalk").ChalkInstance;
13
- export declare const boldGrey: import("chalk").ChalkInstance;
14
- export declare const yellow: import("chalk").ChalkInstance;
15
- export declare const dimYellow: import("chalk").ChalkInstance;
16
- export declare const boldYellow: import("chalk").ChalkInstance;
17
- export declare const inverseYellow: import("chalk").ChalkInstance;
18
- export declare const green: import("chalk").ChalkInstance;
19
- export declare const dimGreen: import("chalk").ChalkInstance;
20
- export declare const boldGreen: import("chalk").ChalkInstance;
21
- export declare const red: import("chalk").ChalkInstance;
22
- export declare const dimRed: import("chalk").ChalkInstance;
23
- export declare const boldRed: import("chalk").ChalkInstance;
24
- export declare const blue: import("chalk").ChalkInstance;
25
- export declare const dimBlue: import("chalk").ChalkInstance;
26
- export declare const boldBlue: import("chalk").ChalkInstance;
27
- export declare const magenta: import("chalk").ChalkInstance;
28
- export declare const dimMagenta: import("chalk").ChalkInstance;
29
- export declare const boldMagenta: import("chalk").ChalkInstance;
30
- export declare const cyan: import("chalk").ChalkInstance;
31
- export declare const dimCyan: import("chalk").ChalkInstance;
32
- export declare const boldCyan: import("chalk").ChalkInstance;
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;
@@ -1,5 +1,5 @@
1
1
  import tty from 'node:tty';
2
- import chalk from 'chalk';
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 'chalk'
11
+ // 2. Easier/shorter to import, rather than from 'ansis'
12
12
  // export type ColorFn = (...args: (string | number)[]) => string
13
- export const white = chalk.white;
14
- export const dimWhite = chalk.dim.white;
15
- export const boldWhite = chalk.bold.white;
16
- export const inverseWhite = chalk.inverse.white;
17
- export const grey = chalk.grey;
18
- export const dimGrey = chalk.dim.grey;
19
- export const boldGrey = chalk.bold.grey;
20
- export const yellow = chalk.yellow;
21
- export const dimYellow = chalk.dim.yellow;
22
- export const boldYellow = chalk.bold.yellow;
23
- export const inverseYellow = chalk.inverse.yellow;
24
- export const green = chalk.green;
25
- export const dimGreen = chalk.dim.green;
26
- export const boldGreen = chalk.bold.green;
27
- export const red = chalk.red;
28
- export const dimRed = chalk.dim.red;
29
- export const boldRed = chalk.bold.red;
30
- export const blue = chalk.blue;
31
- export const dimBlue = chalk.dim.blue;
32
- export const boldBlue = chalk.bold.blue;
33
- export const magenta = chalk.magenta;
34
- export const dimMagenta = chalk.dim.magenta;
35
- export const boldMagenta = chalk.bold.magenta;
36
- export const cyan = chalk.cyan;
37
- export const dimCyan = chalk.dim.cyan;
38
- export const boldCyan = chalk.bold.cyan;
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;
@@ -1,11 +1,12 @@
1
- import type { DumpOptions } from 'js-yaml';
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?: DumpOptions): void;
6
- writeYamlAsync(filePath: string, data: any, opt?: DumpOptions): Promise<void>;
7
- outputYaml(filePath: string, data: any, opt?: DumpOptions): void;
8
- outputYamlAsync(filePath: string, data: any, opt?: DumpOptions): Promise<void>;
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 yaml from 'js-yaml';
3
+ import { parse, stringify } from 'yaml';
4
4
  import { fs2 } from './fs2.js';
5
5
  class Yaml2 {
6
6
  readYaml(filePath) {
7
- return yaml.load(fs.readFileSync(filePath, 'utf8'));
7
+ return parse(fs.readFileSync(filePath, 'utf8'));
8
8
  }
9
9
  async readYamlAsync(filePath) {
10
- return yaml.load(await fsp.readFile(filePath, 'utf8'));
10
+ return parse(await fsp.readFile(filePath, 'utf8'));
11
11
  }
12
12
  writeYaml(filePath, data, opt) {
13
- const str = yaml.dump(data, opt);
13
+ const str = stringify(data, opt);
14
14
  fs.writeFileSync(filePath, str);
15
15
  }
16
16
  async writeYamlAsync(filePath, data, opt) {
17
- const str = yaml.dump(data, opt);
17
+ const str = stringify(data, opt);
18
18
  await fsp.writeFile(filePath, str);
19
19
  }
20
20
  outputYaml(filePath, data, opt) {
21
- const str = yaml.dump(data, opt);
21
+ const str = stringify(data, opt);
22
22
  fs2.outputFile(filePath, str);
23
23
  }
24
24
  async outputYamlAsync(filePath, data, opt) {
25
- const str = yaml.dump(data, opt);
25
+ const str = stringify(data, opt);
26
26
  await fs2.outputFileAsync(filePath, str);
27
27
  }
28
28
  }
@@ -430,7 +430,7 @@ declare function objectDbEntity<OUT extends BaseDBEntity, EXTRA_KEYS extends Exc
430
430
  } : {
431
431
  updated: BuilderFor<OUT['updated']>;
432
432
  })): JObject<OUT, false>;
433
- declare function record<KS extends JSchema<any, any>, VS extends JSchema<any, any>, Opt extends boolean = SchemaOpt<VS>>(keySchema: KS, valueSchema: VS): JObject<Opt extends true ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>> : Record<SchemaOut<KS>, SchemaOut<VS>>, false>;
433
+ declare function record<KS extends JSchema<any, any>, VS extends JSchema<any, any>, Opt extends boolean = SchemaOpt<VS>>(keySchema: KS, valueSchema: VS): SchemaOut<KS> extends string ? JObject<Opt extends true ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>> : Record<SchemaOut<KS>, SchemaOut<VS>>, false> : never;
434
434
  declare function withRegexKeys<S extends JSchema<any, any>>(keyRegex: RegExp | string, schema: S): JObject<StringMap<SchemaOut<S>>, false>;
435
435
  /**
436
436
  * Builds the object schema with the indicated `keys` and uses the `schema` for their validation.
@@ -647,7 +647,7 @@ export interface JsonBuilderRuleOpt {
647
647
  */
648
648
  name?: string;
649
649
  }
650
- type EnumKeyUnion<T> = T extends readonly (infer U)[] ? U : T extends StringEnum | NumberEnum ? T[keyof T] : never;
650
+ type EnumKeyUnion<T> = T extends readonly (infer U)[] ? `${U & (string | number)}` : T extends StringEnum | NumberEnum ? `${T[keyof T] & (string | number)}` : never;
651
651
  type SchemaOut<S> = S extends JSchema<infer OUT, any> ? OUT : never;
652
652
  type SchemaOpt<S> = S extends JSchema<any, infer Opt> ? (Opt extends true ? true : false) : false;
653
653
  type TupleOut<T extends readonly JSchema<any, any>[]> = {
@@ -964,6 +964,7 @@ function objectDbEntity(props) {
964
964
  }
965
965
  function record(keySchema, valueSchema) {
966
966
  const keyJsonSchema = keySchema.build();
967
+ _assert(keyJsonSchema.type !== 'number' && keyJsonSchema.type !== 'integer', 'record() key schema must validate strings, not numbers. JSON object keys are always strings.');
967
968
  // Check if value schema is optional before build() strips the optionalField flag
968
969
  const isValueOptional = valueSchema.getSchema().optionalField;
969
970
  const valueJsonSchema = valueSchema.build();
package/package.json CHANGED
@@ -1,25 +1,24 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.97.4",
4
+ "version": "15.98.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
- "chalk": "^5",
11
+ "ansis": "^4",
13
12
  "dotenv": "^17",
14
- "js-yaml": "^4",
15
13
  "jsonwebtoken": "^9",
16
14
  "lru-cache": "^11",
17
15
  "tinyglobby": "^0.2",
18
16
  "tslib": "^2",
17
+ "yaml": "^2",
19
18
  "yargs": "^18"
20
19
  },
21
20
  "devDependencies": {
22
- "@typescript/native-preview": "7.0.0-dev.20260201.1",
21
+ "@typescript/native-preview": "7.0.0-dev.20260301.1",
23
22
  "@naturalcycles/dev-lib": "18.4.2"
24
23
  },
25
24
  "exports": {
@@ -1,5 +1,5 @@
1
1
  import tty from 'node:tty'
2
- import chalk from 'chalk'
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 'chalk'
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 = chalk.white
17
- export const dimWhite = chalk.dim.white
18
- export const boldWhite = chalk.bold.white
19
- export const inverseWhite = chalk.inverse.white
20
- export const grey = chalk.grey
21
- export const dimGrey = chalk.dim.grey
22
- export const boldGrey = chalk.bold.grey
23
- export const yellow = chalk.yellow
24
- export const dimYellow = chalk.dim.yellow
25
- export const boldYellow = chalk.bold.yellow
26
- export const inverseYellow = chalk.inverse.yellow
27
- export const green = chalk.green
28
- export const dimGreen = chalk.dim.green
29
- export const boldGreen = chalk.bold.green
30
- export const red = chalk.red
31
- export const dimRed = chalk.dim.red
32
- export const boldRed = chalk.bold.red
33
- export const blue = chalk.blue
34
- export const dimBlue = chalk.dim.blue
35
- export const boldBlue = chalk.bold.blue
36
- export const magenta = chalk.magenta
37
- export const dimMagenta = chalk.dim.magenta
38
- export const boldMagenta = chalk.bold.magenta
39
- export const cyan = chalk.cyan
40
- export const dimCyan = chalk.dim.cyan
41
- export const boldCyan = chalk.bold.cyan
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/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 { DumpOptions } from 'js-yaml'
4
- import yaml from 'js-yaml'
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 yaml.load(fs.readFileSync(filePath, 'utf8')) as T
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 yaml.load(await fsp.readFile(filePath, 'utf8')) as T
25
+ return parse(await fsp.readFile(filePath, 'utf8')) as T
14
26
  }
15
27
 
16
- writeYaml(filePath: string, data: any, opt?: DumpOptions): void {
17
- const str = yaml.dump(data, opt)
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?: DumpOptions): Promise<void> {
22
- const str = yaml.dump(data, opt)
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?: DumpOptions): void {
27
- const str = yaml.dump(data, opt)
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?: DumpOptions): Promise<void> {
32
- const str = yaml.dump(data, opt)
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
  }
@@ -1380,13 +1380,20 @@ function record<
1380
1380
  >(
1381
1381
  keySchema: KS,
1382
1382
  valueSchema: VS,
1383
- ): JObject<
1384
- Opt extends true
1385
- ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>>
1386
- : Record<SchemaOut<KS>, SchemaOut<VS>>,
1387
- false
1388
- > {
1383
+ ): SchemaOut<KS> extends string
1384
+ ? JObject<
1385
+ Opt extends true
1386
+ ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>>
1387
+ : Record<SchemaOut<KS>, SchemaOut<VS>>,
1388
+ false
1389
+ >
1390
+ : never {
1389
1391
  const keyJsonSchema = keySchema.build()
1392
+
1393
+ _assert(
1394
+ keyJsonSchema.type !== 'number' && keyJsonSchema.type !== 'integer',
1395
+ 'record() key schema must validate strings, not numbers. JSON object keys are always strings.',
1396
+ )
1390
1397
  // Check if value schema is optional before build() strips the optionalField flag
1391
1398
  const isValueOptional = (valueSchema as JSchema<any, any>).getSchema().optionalField
1392
1399
  const valueJsonSchema = valueSchema.build()
@@ -1396,18 +1403,13 @@ function record<
1396
1403
  ? { anyOf: [{ isUndefined: true }, valueJsonSchema] }
1397
1404
  : valueJsonSchema
1398
1405
 
1399
- return new JObject<
1400
- Opt extends true
1401
- ? Partial<Record<SchemaOut<KS>, SchemaOut<VS>>>
1402
- : Record<SchemaOut<KS>, SchemaOut<VS>>,
1403
- false
1404
- >([], {
1406
+ return new JObject([], {
1405
1407
  hasIsOfTypeCheck: false,
1406
1408
  keySchema: keyJsonSchema,
1407
1409
  patternProperties: {
1408
1410
  ['^.*$']: finalValueSchema,
1409
1411
  },
1410
- })
1412
+ }) as any
1411
1413
  }
1412
1414
 
1413
1415
  function withRegexKeys<S extends JSchema<any, any>>(
@@ -2151,12 +2153,12 @@ export interface JsonBuilderRuleOpt {
2151
2153
  }
2152
2154
 
2153
2155
  type EnumKeyUnion<T> =
2154
- // array of literals -> union of its elements
2156
+ // array of literals -> union of its elements (stringified)
2155
2157
  T extends readonly (infer U)[]
2156
- ? U
2157
- : // enum object -> union of its values
2158
+ ? `${U & (string | number)}`
2159
+ : // enum object -> union of its values (stringified)
2158
2160
  T extends StringEnum | NumberEnum
2159
- ? T[keyof T]
2161
+ ? `${T[keyof T] & (string | number)}`
2160
2162
  : never
2161
2163
 
2162
2164
  type SchemaOut<S> = S extends JSchema<infer OUT, any> ? OUT : never