@naturalcycles/nodejs-lib 15.145.1 → 15.146.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/csv/csvReader.js +2 -1
- package/dist/fs/json2env.js +2 -3
- package/dist/util/env.util.js +2 -2
- package/dist/zip/zipReader.js +2 -6
- package/package.json +2 -2
- package/src/csv/csvReader.ts +2 -1
- package/src/fs/json2env.ts +2 -3
- package/src/util/env.util.ts +2 -1
- package/src/zip/zipReader.ts +5 -6
package/dist/csv/csvReader.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Inspired by: https://gist.github.com/Jezternz/c8e9fafc2c114e079829974e3764db75
|
|
2
|
+
import { _last } from '@naturalcycles/js-lib/array/array.util.js';
|
|
2
3
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
3
4
|
// export class CSVReader {
|
|
4
5
|
// constructor (cfg: CSVReaderConfig) {
|
|
@@ -37,7 +38,7 @@ export function csvStringToArray(str) {
|
|
|
37
38
|
if (matches[1].length && matches[1] !== ',') {
|
|
38
39
|
arr.push([]);
|
|
39
40
|
}
|
|
40
|
-
arr
|
|
41
|
+
_last(arr).push(matches[2] ? matches[2].replaceAll('""', '"') : matches[3]);
|
|
41
42
|
}
|
|
42
43
|
return arr;
|
|
43
44
|
}
|
package/dist/fs/json2env.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
2
3
|
import { dimGrey } from '../colors/colors.js';
|
|
3
4
|
import { fs2 } from './fs2.js';
|
|
4
5
|
const JSON2ENV_OPT_DEF = {
|
|
@@ -13,9 +14,7 @@ export function json2env(opt) {
|
|
|
13
14
|
...opt,
|
|
14
15
|
};
|
|
15
16
|
if (!fs2.pathExists(jsonPath)) {
|
|
16
|
-
|
|
17
|
-
throw new Error(`Path doesn't exist: ${jsonPath}`);
|
|
18
|
-
}
|
|
17
|
+
_assert(!fail, `Path doesn't exist: ${jsonPath}`);
|
|
19
18
|
if (!silent) {
|
|
20
19
|
console.log(`json2env input file doesn't exist, skipping without error (${jsonPath})`);
|
|
21
20
|
}
|
package/dist/util/env.util.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js';
|
|
1
2
|
import { fs2 } from '../fs/fs2.js';
|
|
2
3
|
/**
|
|
3
4
|
* @example
|
|
@@ -10,8 +11,7 @@ export function requireEnvKeys(...keys) {
|
|
|
10
11
|
// oxlint-disable-next-line unicorn/no-array-reduce
|
|
11
12
|
return keys.reduce((r, k) => {
|
|
12
13
|
const v = process.env[k];
|
|
13
|
-
|
|
14
|
-
throw new Error(`${k} env variable is required, but missing`);
|
|
14
|
+
_assert(v, `${k} env variable is required, but missing`);
|
|
15
15
|
r[k] = v;
|
|
16
16
|
return r;
|
|
17
17
|
}, {});
|
package/dist/zip/zipReader.js
CHANGED
|
@@ -391,9 +391,7 @@ function decodeBuffer(buf, hasUtf8Flag) {
|
|
|
391
391
|
}
|
|
392
392
|
function assertPathInside(root, fileName) {
|
|
393
393
|
const targetPath = path.resolve(root, fileName);
|
|
394
|
-
|
|
395
|
-
throw new Error(`zip entry escapes destination directory: ${fileName}`);
|
|
396
|
-
}
|
|
394
|
+
_assert(targetPath === root || targetPath.startsWith(root + path.sep), `zip entry escapes destination directory: ${fileName}`);
|
|
397
395
|
return targetPath;
|
|
398
396
|
}
|
|
399
397
|
class FileSource {
|
|
@@ -413,9 +411,7 @@ class FileSource {
|
|
|
413
411
|
let read = 0;
|
|
414
412
|
while (read < length) {
|
|
415
413
|
const { bytesRead } = await this.fileHandle.read(buf, read, length - read, position + read);
|
|
416
|
-
|
|
417
|
-
throw new Error(`unexpected EOF: read ${read} of ${length} bytes at offset ${position}`);
|
|
418
|
-
}
|
|
414
|
+
_assert(bytesRead, `unexpected EOF: read ${read} of ${length} bytes at offset ${position}`);
|
|
419
415
|
read += bytesRead;
|
|
420
416
|
}
|
|
421
417
|
return buf;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/nodejs-lib",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.146.0",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@naturalcycles/js-lib": "^15",
|
|
7
7
|
"@standard-schema/spec": "^1",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"yaml": "^2"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@naturalcycles/dev-lib": "
|
|
17
|
+
"@naturalcycles/dev-lib": "20.73.0",
|
|
18
18
|
"typescript": "^7"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
package/src/csv/csvReader.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Inspired by: https://gist.github.com/Jezternz/c8e9fafc2c114e079829974e3764db75
|
|
2
2
|
|
|
3
|
+
import { _last } from '@naturalcycles/js-lib/array/array.util.js'
|
|
3
4
|
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
4
5
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
5
6
|
|
|
@@ -65,7 +66,7 @@ export function csvStringToArray(str: string): string[][] {
|
|
|
65
66
|
if (matches[1]!.length && matches[1] !== ',') {
|
|
66
67
|
arr.push([])
|
|
67
68
|
}
|
|
68
|
-
arr
|
|
69
|
+
_last(arr).push(matches[2] ? matches[2].replaceAll('""', '"') : matches[3])
|
|
69
70
|
}
|
|
70
71
|
return arr
|
|
71
72
|
}
|
package/src/fs/json2env.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
2
3
|
import type { AnyObject } from '@naturalcycles/js-lib/types'
|
|
3
4
|
import { dimGrey } from '../colors/colors.js'
|
|
4
5
|
import { fs2 } from './fs2.js'
|
|
@@ -47,9 +48,7 @@ export function json2env(opt: Json2EnvOptions): void {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
if (!fs2.pathExists(jsonPath)) {
|
|
50
|
-
|
|
51
|
-
throw new Error(`Path doesn't exist: ${jsonPath}`)
|
|
52
|
-
}
|
|
51
|
+
_assert(!fail, `Path doesn't exist: ${jsonPath}`)
|
|
53
52
|
|
|
54
53
|
if (!silent) {
|
|
55
54
|
console.log(`json2env input file doesn't exist, skipping without error (${jsonPath})`)
|
package/src/util/env.util.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { _assert } from '@naturalcycles/js-lib/error/assert.js'
|
|
1
2
|
import type { ValuesOf } from '@naturalcycles/js-lib/types'
|
|
2
3
|
import { fs2 } from '../fs/fs2.js'
|
|
3
4
|
|
|
@@ -15,7 +16,7 @@ export function requireEnvKeys<T extends readonly string[]>(
|
|
|
15
16
|
return keys.reduce(
|
|
16
17
|
(r, k) => {
|
|
17
18
|
const v = process.env[k]
|
|
18
|
-
|
|
19
|
+
_assert(v, `${k} env variable is required, but missing`)
|
|
19
20
|
r[k as ValuesOf<T>] = v
|
|
20
21
|
return r
|
|
21
22
|
},
|
package/src/zip/zipReader.ts
CHANGED
|
@@ -477,9 +477,10 @@ function decodeBuffer(buf: Buffer, hasUtf8Flag: boolean): string {
|
|
|
477
477
|
|
|
478
478
|
function assertPathInside(root: string, fileName: string): string {
|
|
479
479
|
const targetPath = path.resolve(root, fileName)
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
_assert(
|
|
481
|
+
targetPath === root || targetPath.startsWith(root + path.sep),
|
|
482
|
+
`zip entry escapes destination directory: ${fileName}`,
|
|
483
|
+
)
|
|
483
484
|
return targetPath
|
|
484
485
|
}
|
|
485
486
|
|
|
@@ -510,9 +511,7 @@ class FileSource implements ZipSource {
|
|
|
510
511
|
let read = 0
|
|
511
512
|
while (read < length) {
|
|
512
513
|
const { bytesRead } = await this.fileHandle.read(buf, read, length - read, position + read)
|
|
513
|
-
|
|
514
|
-
throw new Error(`unexpected EOF: read ${read} of ${length} bytes at offset ${position}`)
|
|
515
|
-
}
|
|
514
|
+
_assert(bytesRead, `unexpected EOF: read ${read} of ${length} bytes at offset ${position}`)
|
|
516
515
|
read += bytesRead
|
|
517
516
|
}
|
|
518
517
|
return buf
|