@naturalcycles/nodejs-lib 15.129.1 → 15.130.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/fs/fs2.d.ts CHANGED
@@ -24,11 +24,15 @@ declare class FS2 {
24
24
  readJsonAsync<T = unknown>(filePath: string): Promise<T>;
25
25
  writeFile(filePath: string, data: string | Buffer, opt?: WriteFileOptions): void;
26
26
  writeFileAsync(filePath: string, data: string | Buffer, opt?: WriteFileOptions): Promise<void>;
27
+ writePrettyJson(filePath: string, data: any): void;
27
28
  writeJson(filePath: string, data: any, opt?: JsonOptions): void;
29
+ writePrettyJsonAsync(filePath: string, data: any): Promise<void>;
28
30
  writeJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
29
31
  appendFile(filePath: string, data: string | Buffer): void;
30
32
  appendFileAsync(filePath: string, data: string | Buffer): Promise<void>;
33
+ outputPrettyJson(filePath: string, data: any): void;
31
34
  outputJson(filePath: string, data: any, opt?: JsonOptions): void;
35
+ outputPrettyJsonAsync(filePath: string, data: any): Promise<void>;
32
36
  outputJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
33
37
  outputFile(filePath: string, data: string | Buffer): void;
34
38
  outputFileAsync(filePath: string, data: string | Buffer): Promise<void>;
package/dist/fs/fs2.js CHANGED
@@ -61,10 +61,16 @@ class FS2 {
61
61
  async writeFileAsync(filePath, data, opt) {
62
62
  await fsp.writeFile(filePath, data, opt);
63
63
  }
64
+ writePrettyJson(filePath, data) {
65
+ this.writeJson(filePath, data, prettyJsonOptions);
66
+ }
64
67
  writeJson(filePath, data, opt) {
65
68
  const str = stringify(data, opt);
66
69
  fs.writeFileSync(filePath, str);
67
70
  }
71
+ async writePrettyJsonAsync(filePath, data) {
72
+ await this.writeJsonAsync(filePath, data, prettyJsonOptions);
73
+ }
68
74
  async writeJsonAsync(filePath, data, opt) {
69
75
  const str = stringify(data, opt);
70
76
  await fsp.writeFile(filePath, str);
@@ -75,10 +81,16 @@ class FS2 {
75
81
  async appendFileAsync(filePath, data) {
76
82
  await fsp.appendFile(filePath, data);
77
83
  }
84
+ outputPrettyJson(filePath, data) {
85
+ this.outputJson(filePath, data, prettyJsonOptions);
86
+ }
78
87
  outputJson(filePath, data, opt) {
79
88
  const str = stringify(data, opt);
80
89
  this.outputFile(filePath, str);
81
90
  }
91
+ async outputPrettyJsonAsync(filePath, data) {
92
+ await this.outputJsonAsync(filePath, data, prettyJsonOptions);
93
+ }
82
94
  async outputJsonAsync(filePath, data, opt) {
83
95
  const str = stringify(data, opt);
84
96
  await this.outputFileAsync(filePath, str);
@@ -266,6 +278,7 @@ class FS2 {
266
278
  createReadStream = fs.createReadStream;
267
279
  }
268
280
  export const fs2 = new FS2();
281
+ const prettyJsonOptions = { spaces: 2 };
269
282
  function stringify(data, opt) {
270
283
  // If pretty-printing is enabled (spaces) - also add a newline at the end (to match our prettier config)
271
284
  return JSON.stringify(data, null, opt?.spaces) + (opt?.spaces ? '\n' : '');
@@ -24,7 +24,7 @@ export function secretsDecrypt(dir, file, encKeyBuffer, del = false, jsonMode =
24
24
  _assert(!filename.endsWith('.plain.json'), `${path.basename(filename)} MUST NOT end with '.plain.json'`);
25
25
  plainFilename = filename.replace('.json', '.plain.json');
26
26
  const json = decryptObject(fs2.readJson(filename), encKeyBuffer);
27
- fs2.writeJson(plainFilename, json, { spaces: 2 });
27
+ fs2.writePrettyJson(plainFilename, json);
28
28
  }
29
29
  else {
30
30
  const enc = fs.readFileSync(filename);
@@ -23,7 +23,7 @@ export function secretsEncrypt(pattern, file, encKeyBuffer, del = false, jsonMod
23
23
  _assert(filename.endsWith('.plain.json'), `${path.basename(filename)} MUST end with '.plain.json'`);
24
24
  encFilename = filename.replace('.plain', '');
25
25
  const json = encryptObject(fs2.readJson(filename), encKeyBuffer);
26
- fs2.writeJson(encFilename, json, { spaces: 2 });
26
+ fs2.writePrettyJson(encFilename, json);
27
27
  }
28
28
  else {
29
29
  const plain = fs.readFileSync(filename);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.129.1",
4
+ "version": "15.130.1",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
package/src/fs/fs2.ts CHANGED
@@ -77,11 +77,19 @@ class FS2 {
77
77
  await fsp.writeFile(filePath, data, opt)
78
78
  }
79
79
 
80
+ writePrettyJson(filePath: string, data: any): void {
81
+ this.writeJson(filePath, data, prettyJsonOptions)
82
+ }
83
+
80
84
  writeJson(filePath: string, data: any, opt?: JsonOptions): void {
81
85
  const str = stringify(data, opt)
82
86
  fs.writeFileSync(filePath, str)
83
87
  }
84
88
 
89
+ async writePrettyJsonAsync(filePath: string, data: any): Promise<void> {
90
+ await this.writeJsonAsync(filePath, data, prettyJsonOptions)
91
+ }
92
+
85
93
  async writeJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
86
94
  const str = stringify(data, opt)
87
95
  await fsp.writeFile(filePath, str)
@@ -95,11 +103,19 @@ class FS2 {
95
103
  await fsp.appendFile(filePath, data)
96
104
  }
97
105
 
106
+ outputPrettyJson(filePath: string, data: any): void {
107
+ this.outputJson(filePath, data, prettyJsonOptions)
108
+ }
109
+
98
110
  outputJson(filePath: string, data: any, opt?: JsonOptions): void {
99
111
  const str = stringify(data, opt)
100
112
  this.outputFile(filePath, str)
101
113
  }
102
114
 
115
+ async outputPrettyJsonAsync(filePath: string, data: any): Promise<void> {
116
+ await this.outputJsonAsync(filePath, data, prettyJsonOptions)
117
+ }
118
+
103
119
  async outputJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
104
120
  const str = stringify(data, opt)
105
121
  await this.outputFileAsync(filePath, str)
@@ -311,6 +327,8 @@ class FS2 {
311
327
 
312
328
  export const fs2 = new FS2()
313
329
 
330
+ const prettyJsonOptions: JsonOptions = { spaces: 2 }
331
+
314
332
  export interface JsonOptions {
315
333
  spaces?: number
316
334
  }
@@ -49,7 +49,7 @@ export function secretsDecrypt(
49
49
 
50
50
  const json = decryptObject(fs2.readJson(filename), encKeyBuffer)
51
51
 
52
- fs2.writeJson(plainFilename, json, { spaces: 2 })
52
+ fs2.writePrettyJson(plainFilename, json)
53
53
  } else {
54
54
  const enc = fs.readFileSync(filename)
55
55
  const plain = decryptRandomIVBuffer(enc, encKeyBuffer)
@@ -44,7 +44,7 @@ export function secretsEncrypt(
44
44
 
45
45
  const json = encryptObject(fs2.readJson(filename), encKeyBuffer)
46
46
 
47
- fs2.writeJson(encFilename, json, { spaces: 2 })
47
+ fs2.writePrettyJson(encFilename, json)
48
48
  } else {
49
49
  const plain = fs.readFileSync(filename)
50
50
  const enc = encryptRandomIVBuffer(plain, encKeyBuffer)