@wxn0brp/db-storage-csv 0.120.0 → 0.120.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/action.d.ts +1 -0
- package/dist/action.js +17 -9
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +2 -5
package/dist/action.d.ts
CHANGED
package/dist/action.js
CHANGED
|
@@ -2,8 +2,10 @@ import { CustomFileCpu } from "@wxn0brp/db-core";
|
|
|
2
2
|
import { CustomActionsBase } from "@wxn0brp/db-core/base/custom";
|
|
3
3
|
import { parse, stringify } from "csv/sync";
|
|
4
4
|
import { access, mkdir, readdir, readFile, rm, writeFile } from "fs/promises";
|
|
5
|
+
import { version } from "./version.js";
|
|
5
6
|
export class DbStorageCsv extends CustomActionsBase {
|
|
6
7
|
opts;
|
|
8
|
+
version = version;
|
|
7
9
|
constructor(opts) {
|
|
8
10
|
super();
|
|
9
11
|
this.opts = opts;
|
|
@@ -22,27 +24,33 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
22
24
|
const data = await readFile(path, "utf-8");
|
|
23
25
|
const records = parse(data, {
|
|
24
26
|
columns: true,
|
|
25
|
-
cast: true,
|
|
26
27
|
});
|
|
27
28
|
for (const record of records) {
|
|
28
29
|
for (const key of Object.keys(record)) {
|
|
29
30
|
const val = record[key];
|
|
30
|
-
if (val === "") {
|
|
31
|
+
if (val === "" || val === undefined || val === null) {
|
|
31
32
|
delete record[key];
|
|
33
|
+
continue;
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
catch { }
|
|
35
|
+
try {
|
|
36
|
+
record[key] = JSON.parse(val);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// keep as string if not valid JSON
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
return records;
|
|
43
44
|
}
|
|
44
45
|
async write(file, data) {
|
|
45
|
-
const
|
|
46
|
+
const transformed = data.map((row) => {
|
|
47
|
+
const newRow = {};
|
|
48
|
+
for (const [k, v] of Object.entries(row)) {
|
|
49
|
+
newRow[k] = v === undefined ? "" : JSON.stringify(v);
|
|
50
|
+
}
|
|
51
|
+
return newRow;
|
|
52
|
+
});
|
|
53
|
+
const string = stringify(transformed, {
|
|
46
54
|
header: true,
|
|
47
55
|
});
|
|
48
56
|
const path = this._getPath(file);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.120.1";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = "0.120.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-csv",
|
|
3
|
-
"version": "0.120.
|
|
3
|
+
"version": "0.120.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "ValtheraDB Storage CSV",
|
|
@@ -18,16 +18,13 @@
|
|
|
18
18
|
"vdb-adapter",
|
|
19
19
|
"csv"
|
|
20
20
|
],
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"@wxn0brp/db-core": "^0.12.0"
|
|
23
|
-
},
|
|
24
21
|
"dependencies": {
|
|
22
|
+
"@wxn0brp/db-core": "^0.12.2",
|
|
25
23
|
"csv": "^6.6.3"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
26
|
"@types/bun": "*",
|
|
29
27
|
"@wxn0brp/biome": "*",
|
|
30
|
-
"@wxn0brp/db-core": "^0.12.0",
|
|
31
28
|
"tsc-alias": "^1",
|
|
32
29
|
"typescript": "^7"
|
|
33
30
|
},
|