@naturalcycles/nodejs-lib 15.99.0 → 15.101.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.
@@ -1,8 +1,9 @@
1
1
  import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToStringOptions } from 'yaml';
2
+ export type YamlParseOptions = ParseOptions & DocumentOptions & SchemaOptions;
2
3
  export type YamlStringifyOptions = DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions;
3
4
  declare class Yaml2 {
4
- readYaml<T = unknown>(filePath: string): T;
5
- readYamlAsync<T = unknown>(filePath: string): Promise<T>;
5
+ readYaml<T = unknown>(filePath: string, opt?: YamlParseOptions): T;
6
+ readYamlAsync<T = unknown>(filePath: string, opt?: YamlParseOptions): Promise<T>;
6
7
  writeYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void;
7
8
  writeYamlAsync(filePath: string, data: any, opt?: YamlStringifyOptions): Promise<void>;
8
9
  outputYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void;
package/dist/fs/yaml2.js CHANGED
@@ -3,11 +3,11 @@ import fsp from 'node:fs/promises';
3
3
  import { parse, stringify } from 'yaml';
4
4
  import { fs2 } from './fs2.js';
5
5
  class Yaml2 {
6
- readYaml(filePath) {
7
- return parse(fs.readFileSync(filePath, 'utf8'));
6
+ readYaml(filePath, opt) {
7
+ return parse(fs.readFileSync(filePath, 'utf8'), opt);
8
8
  }
9
- async readYamlAsync(filePath) {
10
- return parse(await fsp.readFile(filePath, 'utf8'));
9
+ async readYamlAsync(filePath, opt) {
10
+ return parse(await fsp.readFile(filePath, 'utf8'), opt);
11
11
  }
12
12
  writeYaml(filePath, data, opt) {
13
13
  const str = stringify(data, opt);
@@ -336,11 +336,11 @@ export declare class JObject<OUT extends AnyObject, Opt extends boolean = false>
336
336
  * When set, the validation will not strip away properties that are not specified explicitly in the schema.
337
337
  */
338
338
  allowAdditionalProperties(): this;
339
- extend<P extends Record<string, JSchema<any, any>>>(props: P): JObject<Override<OUT, {
339
+ extend<P extends Record<string, JSchema<any, any>>>(props: P): JObject<Expand<Override<OUT, {
340
340
  [K in keyof P as P[K] extends JSchema<any, infer IsOpt> ? IsOpt extends true ? never : K : never]: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never;
341
341
  } & {
342
342
  [K in keyof P as P[K] extends JSchema<any, infer IsOpt> ? IsOpt extends true ? K : never : never]?: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never;
343
- }>, false>;
343
+ }>>, false>;
344
344
  /**
345
345
  * Concatenates another schema to the current schema.
346
346
  *
@@ -352,11 +352,11 @@ export declare class JObject<OUT extends AnyObject, Opt extends boolean = false>
352
352
  /**
353
353
  * Extends the current schema with `id`, `created` and `updated` according to NC DB conventions.
354
354
  */
355
- dbEntity(): JObject<Override<OUT, {
355
+ dbEntity(): JObject<Expand<Override<OUT, {
356
356
  id: string;
357
357
  created: UnixTimestamp;
358
358
  updated: UnixTimestamp;
359
- } & {}>, false>;
359
+ } & {}>>, false>;
360
360
  minProperties(minProperties: number): this;
361
361
  maxProperties(maxProperties: number): this;
362
362
  exclusiveProperties(propNames: readonly (keyof OUT & string)[]): this;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.99.0",
4
+ "version": "15.101.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
package/src/fs/yaml2.ts CHANGED
@@ -10,6 +10,8 @@ import type {
10
10
  import { parse, stringify } from 'yaml'
11
11
  import { fs2 } from './fs2.js'
12
12
 
13
+ export type YamlParseOptions = ParseOptions & DocumentOptions & SchemaOptions
14
+
13
15
  export type YamlStringifyOptions = DocumentOptions &
14
16
  SchemaOptions &
15
17
  ParseOptions &
@@ -17,12 +19,12 @@ export type YamlStringifyOptions = DocumentOptions &
17
19
  ToStringOptions
18
20
 
19
21
  class Yaml2 {
20
- readYaml<T = unknown>(filePath: string): T {
21
- return parse(fs.readFileSync(filePath, 'utf8')) as T
22
+ readYaml<T = unknown>(filePath: string, opt?: YamlParseOptions): T {
23
+ return parse(fs.readFileSync(filePath, 'utf8'), opt) as T
22
24
  }
23
25
 
24
- async readYamlAsync<T = unknown>(filePath: string): Promise<T> {
25
- return parse(await fsp.readFile(filePath, 'utf8')) as T
26
+ async readYamlAsync<T = unknown>(filePath: string, opt?: YamlParseOptions): Promise<T> {
27
+ return parse(await fsp.readFile(filePath, 'utf8'), opt) as T
26
28
  }
27
29
 
28
30
  writeYaml(filePath: string, data: any, opt?: YamlStringifyOptions): void {
@@ -1071,23 +1071,25 @@ export class JObject<OUT extends AnyObject, Opt extends boolean = false> extends
1071
1071
  extend<P extends Record<string, JSchema<any, any>>>(
1072
1072
  props: P,
1073
1073
  ): JObject<
1074
- Override<
1075
- OUT,
1076
- {
1077
- // required keys
1078
- [K in keyof P as P[K] extends JSchema<any, infer IsOpt>
1079
- ? IsOpt extends true
1080
- ? never
1081
- : K
1082
- : never]: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never
1083
- } & {
1084
- // optional keys
1085
- [K in keyof P as P[K] extends JSchema<any, infer IsOpt>
1086
- ? IsOpt extends true
1087
- ? K
1088
- : never
1089
- : never]?: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never
1090
- }
1074
+ Expand<
1075
+ Override<
1076
+ OUT,
1077
+ {
1078
+ // required keys
1079
+ [K in keyof P as P[K] extends JSchema<any, infer IsOpt>
1080
+ ? IsOpt extends true
1081
+ ? never
1082
+ : K
1083
+ : never]: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never
1084
+ } & {
1085
+ // optional keys
1086
+ [K in keyof P as P[K] extends JSchema<any, infer IsOpt>
1087
+ ? IsOpt extends true
1088
+ ? K
1089
+ : never
1090
+ : never]?: P[K] extends JSchema<infer OUT2, any> ? OUT2 : never
1091
+ }
1092
+ >
1091
1093
  >,
1092
1094
  false
1093
1095
  > {