@wxn0brp/db-storage-csv 0.100.0 → 0.120.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/README.md +1 -1
- package/dist/action.js +40 -5
- package/dist/index.js +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
package/dist/action.js
CHANGED
|
@@ -20,10 +20,31 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
20
20
|
async read(file) {
|
|
21
21
|
const path = this._getPath(file);
|
|
22
22
|
const data = await readFile(path, "utf-8");
|
|
23
|
-
|
|
23
|
+
const records = parse(data, {
|
|
24
|
+
columns: true,
|
|
25
|
+
cast: true,
|
|
26
|
+
});
|
|
27
|
+
for (const record of records) {
|
|
28
|
+
for (const key of Object.keys(record)) {
|
|
29
|
+
const val = record[key];
|
|
30
|
+
if (val === "") {
|
|
31
|
+
delete record[key];
|
|
32
|
+
}
|
|
33
|
+
else if (typeof val === "string" &&
|
|
34
|
+
(val.startsWith("{") || val.startsWith("["))) {
|
|
35
|
+
try {
|
|
36
|
+
record[key] = JSON.parse(val);
|
|
37
|
+
}
|
|
38
|
+
catch { }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return records;
|
|
24
43
|
}
|
|
25
44
|
async write(file, data) {
|
|
26
|
-
const string = stringify(data, {
|
|
45
|
+
const string = stringify(data, {
|
|
46
|
+
header: true,
|
|
47
|
+
});
|
|
27
48
|
const path = this._getPath(file);
|
|
28
49
|
await writeFile(path, string);
|
|
29
50
|
}
|
|
@@ -32,6 +53,7 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
32
53
|
if (this.opts.file) {
|
|
33
54
|
try {
|
|
34
55
|
await access(path);
|
|
56
|
+
return false;
|
|
35
57
|
}
|
|
36
58
|
catch (error) {
|
|
37
59
|
await writeFile(path, "");
|
|
@@ -40,9 +62,12 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
40
62
|
else if (this.opts.dir) {
|
|
41
63
|
try {
|
|
42
64
|
await access(path);
|
|
65
|
+
return false;
|
|
43
66
|
}
|
|
44
67
|
catch (error) {
|
|
45
|
-
await mkdir(path.split("/").slice(0, -1).join("/"), {
|
|
68
|
+
await mkdir(path.split("/").slice(0, -1).join("/"), {
|
|
69
|
+
recursive: true,
|
|
70
|
+
});
|
|
46
71
|
await writeFile(path, "");
|
|
47
72
|
}
|
|
48
73
|
}
|
|
@@ -60,10 +85,20 @@ export class DbStorageCsv extends CustomActionsBase {
|
|
|
60
85
|
}
|
|
61
86
|
async getCollections() {
|
|
62
87
|
if (this.opts.file) {
|
|
63
|
-
return [
|
|
88
|
+
return [
|
|
89
|
+
this.opts.file,
|
|
90
|
+
];
|
|
64
91
|
}
|
|
65
92
|
else if (this.opts.dir) {
|
|
66
|
-
|
|
93
|
+
try {
|
|
94
|
+
const files = await readdir(this.opts.dir, {
|
|
95
|
+
recursive: true,
|
|
96
|
+
});
|
|
97
|
+
return files.map(f => (f.endsWith(".csv") ? f.slice(0, -4) : f));
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
67
102
|
}
|
|
68
103
|
else {
|
|
69
104
|
return [];
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-storage-csv",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.120.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "ValtheraDB Storage CSV",
|
|
@@ -19,16 +19,17 @@
|
|
|
19
19
|
"csv"
|
|
20
20
|
],
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@wxn0brp/db-core": "
|
|
22
|
+
"@wxn0brp/db-core": "^0.12.0"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"csv": "^6.
|
|
25
|
+
"csv": "^6.6.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/
|
|
29
|
-
"@wxn0brp/
|
|
30
|
-
"
|
|
31
|
-
"
|
|
28
|
+
"@types/bun": "*",
|
|
29
|
+
"@wxn0brp/biome": "*",
|
|
30
|
+
"@wxn0brp/db-core": "^0.12.0",
|
|
31
|
+
"tsc-alias": "^1",
|
|
32
|
+
"typescript": "^7"
|
|
32
33
|
},
|
|
33
34
|
"files": [
|
|
34
35
|
"dist"
|